skillfed

pytest-localserver

pytest plugin to test server connections locally.

pytest-localserver v0.10.0 395.9K downloads/30d#6,978 on PyPI37
Permissive license MIT Active released

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-localserver

uv

uv add pytest-localserver

poetry

poetry add pytest-localserver

Installing 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

Development Status :: 4 - BetaFramework :: PytestIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Testing

Tags

pytest local server testingmock http server pytesttest server localhostpytest smtp server fixturehttp request testing without mocking
pytest-pluginintegration-testinghttp-testing

More Testing packages