API Reference

Pytest

Mature full-featured Python testing framework with fixtures, parametrization, and plugins.

Official Documentation ↗
CompatibilityThis documentation covers version v8.3. Check the official docs for the latest API surface.

Installation

pippip install pytest

Methods

Pytest is a mature, full-featured Python testing framework that makes it easy to write small, readable tests, yet scales to support complex functional testing with fixtures, parametrization, and a rich plugin ecosystem.

Key Features

  • Plain asserts: No special assert functions needed
  • Fixtures: Reusable, scoped setup via dependency injection
  • Parametrization: Data-driven test generation
  • Markers: Select, skip, and expect failures
  • Plugins: Hundreds of plugins and hooks

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://docs.pytest.org/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:02.455Z.

  • Security ¶ If you have found an issue that you believe is a security vulnerability, please do not create an issue – instead, report it via a new security advisory . (https://docs.pytest.org/)

FAQ

How do fixtures differ from setup/teardown?
Fixtures are explicit, reusable, and dependency-injected by name. They support scopes (function, module, session), yield for teardown, and parametrization. This is more flexible and composable than classic xUnit setup/teardown methods.
What is conftest.py for?
conftest.py holds shared fixtures and hooks available to tests in its directory and below without imports. It is the standard place for session-scoped fixtures, command-line options, and plugin hooks.
How do I run a subset of tests?
Use node IDs, markers, or keyword expressions: pytest tests/test_user.py::test_login, pytest -m slow, or pytest -k 'login and not admin'. Combine with markers defined in pytest.ini or pyproject.toml.