pytest#
pytest is a powerful testing framework for Python. It supports unit tests, doctests, and advanced features like fixtures and plugins. In this template, pytest is run with:
hatch run test
hatch run test-no-cov
Configuration#
Pytest settings are in the [tool.pytest.ini_options] section of pyproject.toml].
Doctest integration and coverage are enabled by default.
Extended Testing#
To step up in the game, an extended test environment and the command hatch run test:extended are available to
verify the package on different Python versions and under different conditions thanks to the pytest plugins:
pytest-randomlythat randomizes the test order;pytest-rerunfailuresthat re-runs tests to eliminate intermittent failures;pytest-xdistthat parallelizes the test suite and reduce runtime, to help the previous points that increase the workload;The file
pyproject.tomlincludes configuration for them.
Further Reading#
Alternatives#
Other Python testing frameworks include: