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
- Detailed summary report
- 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
- Fault Handler
- Warning about unraisable exceptions and unhandled thread exceptions
- Creating JUnitXML format files
- Creating resultlog format files
- Sending test report to online pastebin service
- Early loading plugins
- 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
- What fixtures are
- “Requesting” fixtures
- Autouse fixtures (fixtures you don’t have to request)
- Scope: sharing fixtures across classes, modules, packages or session
- Fixture errors
- Teardown/Cleanup (AKA Fixture finalization)
- Safe teardowns
- Fixture availability
- Sharing test data
- Fixture instantiation order
- Running multiple
assert
statements safely - Fixtures can introspect the requesting test context
- Using markers to pass data to fixtures
- Factories as fixtures
- Parametrizing fixtures
- Using marks with parametrized fixtures
- Modularity: using fixtures from a fixture function
- Automatic grouping of tests by fixture instances
- Use fixtures in classes and modules with
usefixtures
- Overriding fixtures on various levels
- Using fixtures from other projects
- 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
- Plugin discovery order at tool startup
- conftest.py: local per-directory plugins
- Writing your own plugin
- Making your plugin installable by others
- Assertion Rewriting
- Requiring/Loading plugins in a test module or conftest file
- Accessing another plugin by name
- Registering custom markers
- Testing plugins
- Writing hook functions
- Logging
- API Reference
- Good Integration Practices
- Flaky tests
- pytest import mechanisms and
sys.path
/PYTHONPATH
- Configuration
- Examples and customization tricks
- Setting up bash completion
- Backwards Compatibility Policy
- History
- Deprecations and Removals
- Python 2.7 and 3.4 support
- Contribution getting started
- Development Guide
- Sponsor
- pytest for enterprise
- License
- Contact channels
- Historical Notes
- Marker revamp and iteration
- 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()
- “compat” properties
- Talks and Tutorials
- Project examples