pytest-http


Namepytest-http JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/hanzhichao/pytest-http
SummaryFixture "http" for http requests
upload_time2024-08-22 09:13:02
maintainerNone
docs_urlNone
authorHan Zhichao
requires_pythonNone
licenseMIT license
keywords pytest py.test http requests
VCS
bugtrack_url
requirements requests pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-http

![Languate - Python](https://img.shields.io/badge/language-python-blue.svg)
![PyPI - License](https://img.shields.io/pypi/l/pytest-owner)
![PyPI](https://img.shields.io/pypi/v/pytest-owner)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-owner)

Pytest发送HTTP请求

---

### 如何使用

1. 安装 `pytest-http`

使用pip从github安装

```sh
pip install pytest-http
```

2. 使用Fixture函数: http

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

支持base_url配置

```python
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)
```

3. 其他可用配置

```python
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 {}
```

---

- Email: <a href="mailto:superhin@126.com?Subject=Pytest%20Email" target="_blank">`superhin@126.com`</a>
- Blog: <a href="https://www.cnblogs.com/superhin/" target="_blank">`博客园 韩志超`</a>
- 简书: <a href="https://www.jianshu.com/u/0115903ded22" target="_blank">`简书 韩志超`</a>


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hanzhichao/pytest-http",
    "name": "pytest-http",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "pytest, py.test, http, requests",
    "author": "Han Zhichao",
    "author_email": "superhin@126.com",
    "download_url": "https://files.pythonhosted.org/packages/c0/b0/f4416a345027ab59c5d7284cf4e834b5d67ef6da795068eaee86ad292606/pytest_http-0.1.1.tar.gz",
    "platform": null,
    "description": "# pytest-http\n\n![Languate - Python](https://img.shields.io/badge/language-python-blue.svg)\n![PyPI - License](https://img.shields.io/pypi/l/pytest-owner)\n![PyPI](https://img.shields.io/pypi/v/pytest-owner)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-owner)\n\nPytest\u53d1\u9001HTTP\u8bf7\u6c42\n\n---\n\n### \u5982\u4f55\u4f7f\u7528\n\n1. \u5b89\u88c5 `pytest-http`\n\n\u4f7f\u7528pip\u4ecegithub\u5b89\u88c5\n\n```sh\npip install pytest-http\n```\n\n2. \u4f7f\u7528Fixture\u51fd\u6570: http\n\n```python\ndef test_get(http):  # \u6240\u6709\u6570\u636e\n    res = http.get('https://httpbin.org/get?a=1&b=2')\n    print(res.text)\n```\n\n\u652f\u6301base_url\u914d\u7f6e\n\n```python\nimport pytest\n\n\n@pytest.fixture\ndef base_url():\n    # you can use pytest-base-url instead\n    return 'https://httpbin.org'\n\n\ndef test_get(http):  # \u6240\u6709\u6570\u636e\n    res = http.get('/get?a=1&b=2')\n    print(res.text)\n\ndef test_post(http):  # \u6240\u6709\u6570\u636e\n    res = http.get('/post', data=dict(a=1, b=2))\n    print(res.text)\n```\n\n3. \u5176\u4ed6\u53ef\u7528\u914d\u7f6e\n\n```python\nimport pytest\n\n\n@pytest.fixture\ndef http_default_timeout():\n    return 10\n\n\n@pytest.fixture\ndef http_default_headers():\n    return {'Authorization': 'Bearer xxx'}\n\n\n@pytest.fixture\ndef http_default_params():\n    return {}\n\n\n@pytest.fixture\ndef http_default_proxies():\n    return {}\n```\n\n---\n\n- Email: <a href=\"mailto:superhin@126.com?Subject=Pytest%20Email\" target=\"_blank\">`superhin@126.com`</a>\n- Blog: <a href=\"https://www.cnblogs.com/superhin/\" target=\"_blank\">`\u535a\u5ba2\u56ed \u97e9\u5fd7\u8d85`</a>\n- \u7b80\u4e66: <a href=\"https://www.jianshu.com/u/0115903ded22\" target=\"_blank\">`\u7b80\u4e66 \u97e9\u5fd7\u8d85`</a>\n\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Fixture \"http\" for http requests",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/hanzhichao/pytest-http"
    },
    "split_keywords": [
        "pytest",
        " py.test",
        " http",
        " requests"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c0b0f4416a345027ab59c5d7284cf4e834b5d67ef6da795068eaee86ad292606",
                "md5": "aba1350d4475d0f33ef52a2cdf15aaa9",
                "sha256": "86c1f7bb3e2872742a871666eb53f068a48ad2237f3ce5911b18a1eb2a60c2e8"
            },
            "downloads": -1,
            "filename": "pytest_http-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "aba1350d4475d0f33ef52a2cdf15aaa9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3889,
            "upload_time": "2024-08-22T09:13:02",
            "upload_time_iso_8601": "2024-08-22T09:13:02.913291Z",
            "url": "https://files.pythonhosted.org/packages/c0/b0/f4416a345027ab59c5d7284cf4e834b5d67ef6da795068eaee86ad292606/pytest_http-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-22 09:13:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hanzhichao",
    "github_project": "pytest-http",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "pytest",
            "specs": []
        }
    ],
    "lcname": "pytest-http"
}
        
Elapsed time: 0.34274s