Skip to content

hanzhichao/pytest-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pytest-http

Languate - Python PyPI - License PyPI PyPI - Downloads

Pytest发送HTTP请求


如何使用

  1. 安装 pytest-http

使用pip从github安装

pip install pytest-http
  1. 使用Fixture函数: http
def test_get(http):  # 所有数据
    res = http.get('https://httpbin.org/get?a=1&b=2')
    print(res.text)

支持base_url配置

import pytest


@pytest.fixture
def base_url():
    # you can use pytest-base-url instead
    return 'https://httpbin.org'


def test_get(http):  # 所有数据
    res = http.get('/get?a=1&b=2')
    print(res.text)

def test_post(http):  # 所有数据
    res = http.get('/post', data=dict(a=1, b=2))
    print(res.text)
  1. 其他可用配置
import pytest


@pytest.fixture
def http_default_timeout():
    return 10


@pytest.fixture
def http_default_headers():
    return {'Authorization': 'Bearer xxx'}


@pytest.fixture
def http_default_params():
    return {}


@pytest.fixture
def http_default_proxies():
    return {}

About

Pytest plugin for sending http request

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published