Registry / testing / pytest-httpbin

pytest-httpbin

JSON →
library2.1.0pypypiunverified

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.

pip install pytest-httpbin requests
INSTALL
IMPORT
SIG · PYTEST-HTTPBIN
P
pytest-httpbin
testingpythonv2.1.0
Install
5.2s avg
Import
Disk
57MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 5.2s · import 0.000s · 58MB
57MB installed
● package 57MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

httpbin
def test_example(httpbin): # httpbin fixture is automatically discovered by pytest and passed as argument response = requests.get(httpbin.url + '/get')
from pytest_httpbin import httpbin
pytest fixtures are automatically discovered and injected into test functions; explicit import is unnecessary and will lead to `ModuleNotFoundError` or incorrect usage.
httpbin_secure
def test_secure(httpbin_secure, httpbin_ca_bundle): # httpbin_secure fixture for HTTPS tests response = requests.get(httpbin_secure.url + '/get', verify=httpbin_ca_bundle)
from pytest_httpbin import httpbin_secure
Same as 'httpbin', fixtures are discovered by pytest, not imported directly.
httpbin_ca_bundle
def test_ca_bundle(httpbin_secure, httpbin_ca_bundle): # httpbin_ca_bundle provides path to CA certificate for HTTPS verification response = requests.get(httpbin_secure.url + '/get', verify=httpbin_ca_bundle)
from pytest_httpbin import httpbin_ca_bundle
Same as 'httpbin', fixtures are discovered by pytest, not imported directly.

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.

import pytest import requests def test_get_request(httpbin): """Test a simple GET request against the local httpbin instance.""" print(f"Testing against httpbin at: {httpbin.url}") response = requests.get(httpbin.url + '/get') response.raise_for_status() data = response.json() assert data['headers']['Host'] == httpbin.host def test_post_request(httpbin): """Test a POST request.""" payload = {'key': 'value'} response = requests.post(httpbin.url + '/post', json=payload) response.raise_for_status() data = response.json() assert data['json'] == payload def test_secure_request(httpbin_secure, httpbin_ca_bundle): """Test an HTTPS request with CA bundle verification.""" print(f"Testing against secure httpbin at: {httpbin_secure.url}") # Note: requests must be explicitly told to verify with the provided CA bundle response = requests.get(httpbin_secure.url + '/get', verify=httpbin_ca_bundle) response.raise_for_status() data = response.json() assert data['headers']['Host'] == httpbin_secure.host # To run this, save as `test_httpbin_example.py` and run `pytest` in your terminal.
Debug
Known issues
breakingVersion 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).
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`.
affects: >=2.0.0
breakingVersion 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.
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.
affects: >=1.0.0
gotchaWhen 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.
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.
affects: all
gotchaThe 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.
fix
To specify a port, define the environment variable before running pytest, e.g., `HTTPBIN_HTTP_PORT=8000 pytest`.
affects: >=0.3.0
Upgrade
Version history
2.1.0latest on PyPI · released Sep 18, 2024
Audit
Dependencies
pytestrequiredpytest-httpbin is a plugin for pytest, requiring it to run tests.
Agent activity
8 hits · last 30 days
node
8
Resources
pytest-httpbin — pip install pytest-httpbin · libregistry