pytest-localserver
pytest plugin to test server connections locally.
What it is and what it does
pytest-localserver is a pytest plugin that provides fixtures for running local HTTP and SMTP servers during tests. Instead of mocking HTTP calls or relying on external test servers, you get a real server running on localhost that you can control—setting response codes, headers, content, and inspecting incoming requests. It works with werkzeug to handle the underlying HTTP protocol.
The plugin includes httpserver and httpsserver fixtures for HTTP/HTTPS testing, plus an smtpserver fixture for testing mail-sending code. You configure what each server should return, make your code talk to it, and then verify the requests were made correctly. It also supports running a WSGI application on the test server, making it flexible for testing against different backend behaviors.
Use it for:
- Test a web scraper or API client against a controlled local server instead of a live endpoint.
- Verify your code handles HTTP error responses gracefully without external dependencies.
- Test email-sending code by inspecting what was posted to a local SMTP server.
- Test request headers and POST data handling by examining the server's received requests.
- Run integration tests for code that makes network calls without mocking the underlying HTTP layer.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides pytest fixtures that spin up local HTTP and SMTP servers for testing code that makes real network requests without relying on external services or mocking.
Yes. Low install friction, actively maintained, no known vulnerabilities, and solves a real testing problem—letting you test network-dependent code with a real local server rather than mocks.
Install
pytest-localserver on PyPI
pip
pip install pytest-localserveruv
uv add pytest-localserverpoetry
poetry add pytest-localserverInstalling pytest-localserver
Before you install
Low friction install with a single runtime dependency (werkzeug). Actively maintained with recent releases; last commit was 2026-07-14 and the package is marked active.
License in practice
MIT license permits commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install pytest-localserver
def test_scrape(httpserver):
httpserver.serve_content("<html>test</html>", code=200)
assert httpserver.url
Requires pytest to be installed; the httpserver fixture is only available within pytest test functions.
Verify before relying
- Whether the package handles urllib, requests, and other HTTP libraries as described in the documentation.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — werkzeug |
| Maintenance | actively maintained — 263 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 395,896/month — #6,978 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_localserver-0.10.0-py3-none-any.whl
Keywords: pytest, server, localhost, http, smtp
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-httpbinProvides a pytest fixture that runs a local…
permissive · top 15,000 on PyPI
pytest-sftpserverA pytest plugin that provides a fixture for…
permissive · top 5,000 on PyPI
pytest_httpserverA pytest fixture and standalone context manager…
unclear · top 5,000 on PyPI
pytest-responsesAutomatically mocks HTTP requests across your…
permissive · top 15,000 on PyPI
mocketMocket is a socket mocking framework that…
permissive · top 15,000 on PyPI
pytest-djangopytest-django integrates Django with pytest,…
permissive · top 1,000 on PyPI
pytest-base-urlA pytest plugin that injects a configurable…
copyleft · top 5,000 on PyPI
pytest-mock-resourcesProvides pytest fixtures that spin up real…
permissive · top 15,000 on PyPI
pytest-dockerpytest-docker provides pytest fixtures that…
permissive · top 5,000 on PyPI