{"library":"pytest-httpbin","title":"pytest-httpbin","description":"pytest-httpbin is a pytest plugin that provides fixtures to easily test your HTTP library against a local, self-hosted copy of httpbin.org. It's currently at version 2.1.0 and has an infrequent, release-as-needed cadence, primarily for compatibility updates with newer Python or pytest versions.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pytest-httpbin requests"],"cli":null},"imports":["def test_example(httpbin):\n    # httpbin fixture is automatically discovered by pytest and passed as argument\n    response = requests.get(httpbin.url + '/get')","def test_secure(httpbin_secure, httpbin_ca_bundle):\n    # httpbin_secure fixture for HTTPS tests\n    response = requests.get(httpbin_secure.url + '/get', verify=httpbin_ca_bundle)","def test_ca_bundle(httpbin_secure, httpbin_ca_bundle):\n    # httpbin_ca_bundle provides path to CA certificate for HTTPS verification\n    response = requests.get(httpbin_secure.url + '/get', verify=httpbin_ca_bundle)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pytest\nimport requests\n\ndef test_get_request(httpbin):\n    \"\"\"Test a simple GET request against the local httpbin instance.\"\"\"\n    print(f\"Testing against httpbin at: {httpbin.url}\")\n    response = requests.get(httpbin.url + '/get')\n    response.raise_for_status()\n    data = response.json()\n    assert data['headers']['Host'] == httpbin.host\n\ndef test_post_request(httpbin):\n    \"\"\"Test a POST request.\"\"\"\n    payload = {'key': 'value'}\n    response = requests.post(httpbin.url + '/post', json=payload)\n    response.raise_for_status()\n    data = response.json()\n    assert data['json'] == payload\n\ndef test_secure_request(httpbin_secure, httpbin_ca_bundle):\n    \"\"\"Test an HTTPS request with CA bundle verification.\"\"\"\n    print(f\"Testing against secure httpbin at: {httpbin_secure.url}\")\n    # Note: requests must be explicitly told to verify with the provided CA bundle\n    response = requests.get(httpbin_secure.url + '/get', verify=httpbin_ca_bundle)\n    response.raise_for_status()\n    data = response.json()\n    assert data['headers']['Host'] == httpbin_secure.host\n\n# To run this, save as `test_httpbin_example.py` and run `pytest` in your terminal.","lang":"python","description":"Create a Python file (e.g., `test_my_app.py`) and define test functions that accept `pytest-httpbin` fixtures like `httpbin`, `httpbin_secure`, and `httpbin_ca_bundle`. Pytest will automatically discover and inject these fixtures. Run the tests using the `pytest` command in your terminal. Ensure `requests` is also installed (`pip install requests`) to make HTTP calls.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}