The pytest framework makes it easy to write small, readable tests, and can scale to support complex functional testing for applications and libraries. PyPI package name: pytest A quick example ¶
funcargs and pytest_funcarg__ @pytest.yield_fixture decorator [pytest] header in setup.cfg Applying marks to @pytest.mark.parametrize parameters @pytest.mark.parametrize argument names as a tuple setup: is now an “autouse fixture” Conditions as strings instead of booleans pytest.set_trace() “compat” properties Talks and Tutorials Books
Getting help on version, option names, environment variables ¶ pytest --version # shows where pytest was imported from pytest --fixtures # show available builtin function arguments pytest -h | --help # show help on command line and config file options
Also, pytest on stackoverflow.com often comes with example answers. For basic examples, see Get Started for basic introductory examples How to write and report assertions in tests for basic assertion examples Fixtures for basic fixture/setup examples How to parametrize fixtures and test functions for basic test function parametrization
How-to guides Core pytest functionality ¶ How to invoke pytest How to write and report assertions in tests How to use fixtures How to mark test functions with attributes How to parametrize fixtures and test functions How to use temporary directories and files in tests How to monkeypatch/mock modules and environments How to run doctests
pytest: helps you write better programs ¶ The pytest framework makes it easy to write small, readable tests, and can scale to support complex functional testing for applications and libraries. pytest requires: Python 3.7+ or PyPy3. PyPI package name: pytest
pytest and other test systems ¶ How to use pytest with an existing test suite How to use unittest -based tests with pytest How to implement xunit-style set-up
In general, pytest is invoked with the command pytest (see below for other ways to invoke pytest). This will execute all tests in all files whose names follow the form test_*.py or *_test.py in the current directory and its subdirectories. More generally, pytest follows standard test discovery rules.