Testing

Libraries for testing codebases and generating test data. Also see awesome-python-testing.

pytest runs your unittest suites unchanged, so switching Python testing frameworks costs no rewrite. Hypothesis and Playwright tests run inside it too.

How to choose:

Listed in editorial order, grouped by use case. Click a column header to re-sort the whole list.

Press / to search. Tags open their category. Click a row for details.

Search and filter

Results

Row number Tags

Frameworks 3 projects

A mature full-featured Python testing tool.
Also see: awesome-pytest
pytest-dev/github.com/pytest-dev/pytest /14,654 stars /
Hypothesis is an advanced QuickCheck-style property-based testing library.
A generic test automation framework.

Test Runners 2 projects

Automatically builds and tests distributions in multiple Python versions.
tox-dev/github.com/tox-dev/tox /3,979 stars /
Flexible test automation for Python.
wntrblm/github.com/wntrblm/nox /1,561 stars /

Browser Automation 3 projects

Python version of the Playwright testing and automation library.
Python bindings for Selenium WebDriver.
SeleniumHQ/github.com/SeleniumHQ/selenium /34,570 stars /
Python framework for web automation & testing, with stealth options.

Load Testing 1 project

Scalable user load testing tool written in Python.
locustio/github.com/locustio/locust /28,249 stars /

API Testing 1 project

Automatic property-based testing of web APIs from OpenAPI or GraphQL schemas.

Mock 5 projects

(Python standard library) A mocking and patching library.
A utility library for mocking out the requests Python library.
getsentry/github.com/getsentry/responses /4,342 stars /
Record and replay HTTP interactions in your tests.
kevin1024/github.com/kevin1024/vcrpy /3,022 stars /
Mock HTTPX with awesome request patterns and response side effects.
lundberg/github.com/lundberg/respx /844 stars /
Travel through time in your tests by mocking the current time at the C level.

Object Factories 2 projects

A test fixtures replacement for Python.
A mock data generation library based on type hints (continuation of pydantic-factories).

Code Coverage 1 project

Code coverage measurement.
coveragepy/github.com/coveragepy/coveragepy /3,423 stars /

Fake Data 2 projects

A Python package that generates fake data.
joke2k/github.com/joke2k/faker /19,470 stars /
A Python library for generating fake but realistic data in multiple languages and locales.
lk-geimfari/github.com/lk-geimfari/mimesis /4,865 stars /

Testing guide

Write pytest tests as plain functions with plain assert statements: pytest's assertion introspection reports the intermediate values when one fails, so there are no assert methods to remember. Share setup through fixtures, which a test requests by name, instead of xUnit-style setup and teardown. pytest also runs unittest-based suites, so you can move an old suite over a test at a time.

Hypothesis tests take a @given decorator with a strategy describing the inputs, and Hypothesis picks which inputs to try, edge cases included. They're still regular functions that pytest or unittest runs.

Playwright's docs call its pytest plugin the recommended way to write end-to-end tests, and every test gets a fresh browser context. Playwright waits for elements to be actionable before each action, and its assertions wait for the expected condition. Locate elements by role and other user-facing attributes, not CSS or XPath, which break as the DOM changes.

Robot Framework writes test cases in a tabular, keyword-driven syntax, builds higher-level keywords from existing ones, and reports results in HTML. Custom keyword libraries are plain Python. In behavior-driven style, a test case reads as a requirement stakeholders who don't code can follow.

tox and Nox both create a virtual environment per Python version or dependency set and run your tests in each. tox defines its environments in a config file. Nox is configured in a noxfile.py, where each session is a Python function, so any logic your test matrix needs is ordinary code.

Selenium drives browsers through WebDriver, a W3C standard, and Selenium Grid runs those tests on other machines and platforms. Its guidelines model each page as a page object that makes no assertions, and use explicit waits for the exact condition each step needs. SeleniumBase builds on Selenium and runs under pytest: its methods wait for an element before acting, and failing tests save screenshots.

A Locust test is a Python program: an HttpUser class whose tasks make requests, so complex user flows are just code.

Schemathesis reads your OpenAPI or GraphQL schema and generates property-based tests from it, with no per-endpoint tests to maintain. Its FAQ recommends the CLI for most users, with a pytest integration for existing suites.

With unittest.mock, patch a name where it's looked up, which isn't always where it's defined. Autospec your mocks, so a test fails when your code calls an API the real object lacks. For the clock, time-machine mocks time functions everywhere they're referenced, where a patch only reaches the import location it targets.

For HTTP, pick by client. responses mocks Requests calls in a test wrapped in @responses.activate, and RESPX mocks HTTPX, with a respx_mock fixture for pytest. VCR.py records real HTTP interactions to a cassette file on the first run and replays them after, across many client libraries.

factory_boy replaces static fixtures with factories, where a test declares only the fields it cares about. It has base classes for Django, SQLAlchemy, and MongoEngine models. Polyfactory instead reads the type hints on dataclasses, TypedDicts, Pydantic models, and msgspec Structs to generate the data.

Run your suite under Coverage.py with coverage run -m pytest, then coverage report prints the results. For most purposes, you need no pytest plugin.

Faker generates names, addresses, and other data per locale. Mimesis covers the same ground, fully typed, and its benchmarks show it faster than Faker.

Random test data makes a failing build hard to reproduce, so seed it: Faker, factory_boy, and Mimesis all take a seed. For more tools, see awesome-python-testing.

Know a project that belongs here?

Tell us what it does and why it stands out.