Full pytest documentation¶
Download latest version as PDF
- Installation and Getting Started
- Usage and Invocations
- Calling pytest through
python -m pytest
- Possible exit codes
- Getting help on version, option names, environment variables
- Stopping after the first (or N) failures
- Specifying tests / selecting tests
- Modifying Python traceback printing
- Dropping to PDB (Python Debugger) on failures
- Dropping to PDB (Python Debugger) at the start of a test
- Setting breakpoints
- Using the builtin breakpoint function
- Profiling test execution duration
- Creating JUnitXML format files
- Creating resultlog format files
- Sending test report to online pastebin service
- Disabling plugins
- Calling pytest from Python code
- Calling pytest through
- Using pytest with an existing test suite
- The writing and reporting of assertions in tests
- pytest fixtures: explicit, modular, scalable
- Fixtures as Function arguments
- Fixtures: a prime example of dependency injection
conftest.py
: sharing fixture functions- Sharing test data
- Scope: sharing a fixture instance across tests in a class, module or session
- Higher-scoped fixtures are instantiated first
- Fixture finalization / executing teardown code
- Fixtures can introspect the requesting test context
- Factories as fixtures
- Parametrizing fixtures
- Using marks with parametrized fixtures
- Modularity: using fixtures from a fixture function
- Automatic grouping of tests by fixture instances
- Using fixtures from classes, modules or projects
- Autouse fixtures (xUnit setup on steroids)
- Overriding fixtures on various levels
- Marking test functions with attributes
- Monkeypatching/mocking modules and environments
- Temporary directories and files
- Capturing of the stdout/stderr output
- Warnings Capture
- Doctest integration for modules and test files
- Skip and xfail: dealing with tests that cannot succeed
- Parametrizing fixtures and test functions
- Cache: working with cross-testrun state
- unittest.TestCase Support
- Running tests written for nose
- classic xunit-style setup
- Installing and Using plugins
- Writing plugins
- Writing hook functions
- Logging
- Reference
- Good Integration Practices
- pytest import mechanisms and
sys.path
/PYTHONPATH
- Configuration
- Examples and customization tricks
- Setting up bash completion
- Backwards Compatibility Policy
- Historical Notes
- cache plugin integrated into the core
- funcargs and
pytest_funcarg__
@pytest.yield_fixture
decorator[pytest]
header insetup.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()
- License
- Contribution getting started
- Development Guide
- Talks and Tutorials
- Project examples
- Some Issues and Questions
- Contact channels