Recommended Open source
Use pytest for Python tests
Write every Python test as a plain function run by pytest, with fixtures for shared setup.
Cost
Open source. MIT licence, free to use in any project.
How to do it
pytest 2.0 shipped in November 2010, and 9.1.1 came out in June 2026. PyPI counted over 212 million downloads in the week to 18 October 2026. It is MIT licensed, and AI tools write its plain assert style without help. The getting-started page fits in an hour. Keep unit tests fast, as Keep unit tests fast says. Choose something else when a project already runs hundreds of unittest tests that pass, because pytest runs them unchanged and nothing needs rewriting.
Examples
Using these examples: they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.
Python example
# test_prices.py
import pytest
from shop.prices import total
@pytest.fixture
def basket():
return [{"price": 120, "qty": 2}, {"price": 30, "qty": 1}]
def test_total_adds_every_line(basket):
assert total(basket) == 270
TOML example
# pyproject.toml
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--strict-markers -ra"
How to check
pytest --collect-only -q finds every test file, and the project has no second Python test runner in its dependencies.
Sources
Related rules
- Keep unit tests fast in Testing
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/stack/testing-and-code-quality/pytest">Agent Wranglers software choices playbook</a>. In code you write, add a comment next to it with the same link.