
pytest documentation
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.8+ or PyPy3. PyPI package name: pytest. A quick example¶
Get Started — pytest documentation
Check out additional pytest resources to help you customize tests for your unique workflow: “ How to invoke pytest ” for command line invocation examples “ How to use pytest with an existing test suite ” for working with pre-existing tests
Full pytest documentation
How to use pytest with an existing test suite. Running an existing test suite with pytest; How to use unittest-based tests with pytest. Benefits out of the box; pytest features in unittest.TestCase subclasses; Mixing pytest fixtures into unittest.TestCase subclasses using marks; Using autouse fixtures and accessing other fixtures
Get Started - pytest documentation
Check out additional pytest resources to help you customize tests for your unique workflow: “ How to invoke pytest ” for command line invocation examples “ How to use pytest with an existing test suite ” for working with preexisting tests
Full pytest documentation
How to use pytest with an existing test suite. Running an existing test suite with pytest; How to use unittest-based tests with pytest. Benefits out of the box; pytest features in unittest.TestCase subclasses; Mixing pytest fixtures into unittest.TestCase subclasses using marks; Using autouse fixtures and accessing other fixtures; How to run ...
How-to guides — pytest documentation
How to use pytest with an existing test suite; How to use unittest-based tests with pytest; How to run tests written for nose; How to implement xunit-style set-up
Usage and Invocations — pytest documentation
Calling pytest.main() will result in importing your tests and any modules that they import. Due to the caching mechanism of python’s import system, making subsequent calls to pytest.main() from the same process will not reflect changes to those files between the calls.
How to invoke pytest
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.
Explanation - pytest documentation
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
Basic patterns and examples - pytest documentation
pytest sets the PYTEST_CURRENT_TEST environment variable when running tests, which can be inspected by process monitoring utilities or libraries like psutil to discover which test got stuck if necessary: