完整的 pytest 文档¶
Download latest version as PDF
这里开始¶
学习指南¶
- 如何调用 pytest
 - 如何编写和报告测试中的断言
 - 如何使用 fixtures
- “Requesting” fixtures
 - Autouse fixture(不必请求的 fixture)
 - 范围:跨类、模块、包或会话共享 fixture
 - Teardown/Cleanup(又名 Fixture 终结)
 - 安全拆解
 - Running multiple 
assertstatements safely - Fixtures can introspect the requesting test context
 - 使用标记将数据传递给 fixture
 - fixtures 工厂
 - 参数化 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
 
 - 如何用属性标记测试函数
 - 如何参数化 fixtures 和测试函数
 - 如何在测试中使用临时目录和文件
 - How to monkeypatch/mock modules and environments
 - How to run doctests
 - 如何重新运行失败的测试并在测试运行之间保持状态
 - 如何管理日志记录
 - How to capture stdout/stderr output
 - How to capture warnings
- Controlling warnings
 @pytest.mark.filterwarnings- Disabling warnings summary
 - Disabling warning capture entirely
 - DeprecationWarning and PendingDeprecationWarning
 - Ensuring code triggers a deprecation warning
 - Asserting warnings with the warns function
 - Recording warnings
 - Additional use cases of warnings in tests
 - Custom failure messages
 - Internal pytest warnings
 - Resource Warnings
 
 - How to use skip and xfail to deal with tests that cannot succeed
 - 如何安装并使用插件
 - 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
- hook function validation and execution
 - firstresult: stop at first non-None result
 - hookwrapper: executing around other hooks
 - Hook function ordering / call example
 - Declaring new hooks
 - Using hooks in pytest_addoption
 - Optionally using hooks from 3rd party plugins
 - Storing data on items across hook functions
 
 - 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
 - 如何设置 bash 自动补全
 
参考指南¶
解释¶
进一步主题¶
- Examples and customization tricks
 - Backwards Compatibility Policy
 - History
 - Python version support
 - Deprecations and Removals
 - Contribution getting started
 - Development Guide
 - Sponsor
 - pytest for enterprise
 - License
 - Contact channels
 - History
 - Historical Notes
- Marker revamp and iteration
 - cache plugin integrated into the core
 - funcargs and 
pytest_funcarg__ @pytest.yield_fixturedecorator[pytest]header insetup.cfg- Applying marks to 
@pytest.mark.parametrizeparameters @pytest.mark.parametrizeargument names as a tuple- setup: is now an “autouse fixture”
 - Conditions as strings instead of booleans
 pytest.set_trace()- “compat” properties
 
 - Talks and Tutorials