{"id":10142,"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.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/kevin1024/pytest-httpbin","tags":["pytest","http","testing","fixtures","plugin"],"install":[{"cmd":"pip install pytest-httpbin requests","lang":"bash","label":"Install stable version (includes requests for quickstart)"}],"dependencies":[{"reason":"pytest-httpbin is a plugin for pytest, requiring it to run tests.","package":"pytest","optional":false}],"imports":[{"note":"pytest fixtures are automatically discovered and injected into test functions; explicit import is unnecessary and will lead to `ModuleNotFoundError` or incorrect usage.","wrong":"from pytest_httpbin import httpbin","symbol":"httpbin","correct":"def test_example(httpbin):\n    # httpbin fixture is automatically discovered by pytest and passed as argument\n    response = requests.get(httpbin.url + '/get')"},{"note":"Same as 'httpbin', fixtures are discovered by pytest, not imported directly.","wrong":"from pytest_httpbin import httpbin_secure","symbol":"httpbin_secure","correct":"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)"},{"note":"Same as 'httpbin', fixtures are discovered by pytest, not imported directly.","wrong":"from pytest_httpbin import httpbin_ca_bundle","symbol":"httpbin_ca_bundle","correct":"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)"}],"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."},"warnings":[{"fix":"Ensure your project uses Python 3.7 or newer before upgrading to `pytest-httpbin` 2.x. If you must use older Python, pin `pytest-httpbin` to `<2.0.0`.","message":"Version 2.0.0 dropped support for older Python versions (2.6, 2.7, 3.4, 3.5, 3.6). It introduced support for Python 3.7+ (up to 3.12).","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Review tests that explicitly manipulate or inspect the SSL certificate provided by `httpbin_secure`. Most users verifying with `httpbin_ca_bundle` should be unaffected.","message":"Version 1.0.0 updated the self-signed certificate provided by `httpbin_secure` to include the IP address in the Subject Alternative Name (SAN). This could be a breaking change for tests that explicitly depended on the certificate *not* having the IP address in the SAN.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always use `verify=httpbin_ca_bundle` (e.g., `requests.get(httpbin_secure.url, verify=httpbin_ca_bundle)`) when making requests to `httpbin_secure` in your tests.","message":"When using the `httpbin_secure` fixture for HTTPS tests, client-side SSL verification will fail unless you explicitly pass the `httpbin_ca_bundle` fixture's path to your HTTP client's `verify` parameter.","severity":"gotcha","affected_versions":"all"},{"fix":"To specify a port, define the environment variable before running pytest, e.g., `HTTPBIN_HTTP_PORT=8000 pytest`.","message":"The httpbin server can be configured to run on a fixed port by setting `HTTPBIN_HTTP_PORT` or `HTTPBIN_HTTPS_PORT` environment variables before running pytest. If not set, a random available port is chosen.","severity":"gotcha","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"pytest fixtures are automatically discovered and injected. Do not `import httpbin`. Instead, declare `httpbin` as an argument in your test function signature, e.g., `def test_my_feature(httpbin): ...`","cause":"You are attempting to explicitly import `httpbin` or other fixtures from `pytest-httpbin`.","error":"ModuleNotFoundError: No module named 'httpbin'"},{"fix":"Ensure your test function accepts the `httpbin_ca_bundle` fixture and pass its value to your HTTP client's `verify` parameter: `requests.get(httpbin_secure.url, verify=httpbin_ca_bundle)`.","cause":"You are making an HTTPS request to `httpbin_secure` without providing the necessary CA certificate for verification, or without disabling verification.","error":"requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed"},{"fix":"Upgrade your Python environment to 3.7 or newer, or downgrade `pytest-httpbin` by pinning it to a version less than 2.0.0 (e.g., `pip install 'pytest-httpbin<2.0.0'`).","cause":"You are trying to install or run `pytest-httpbin` version 2.0.0 or higher on an unsupported Python version.","error":"This version of pytest-httpbin requires Python 3.7 or higher, but you are running Python X.Y."},{"fix":"Ensure you are using a recent `pytest-httpbin` version (>=0.0.4 addressed some issues). If the problem persists, review your test logic for potential server overloading or race conditions, or ensure sufficient time between requests if making many calls in one session.","cause":"This error can occur if the local httpbin server crashes or is prematurely shut down, potentially due to rapid consecutive requests in older versions or specific test setups.","error":"requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine(''))"}]}