Registry / testing / pytest

pytest

JSON →
library9.1.1pypypi✓ verified 28d ago

The standard Python testing framework. Supports fixtures, parametrize, markers, plugins, and assertion rewriting. Current version is 9.0.2. Major versions (8.x, 9.x) have removed long-deprecated features that LLMs still generate.

pip install pytest
INSTALL
IMPORT
SIG · PYTEST
P
pytest
testingpythonv9.1.1
Install
3.5s avg
Import
398ms
Disk
32MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v9.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.417s · 32.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.5s · import 0.380s · 33MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest
import pytest
from py.test import * # py.test CLI name only, not an importable package
Always import as 'import pytest'. The py.test command name is legacy; use the pytest command.
pytest.fixture
@pytest.fixture def my_fixture(): ...
@pytest.yield_fixture def my_fixture(): yield value # yield_fixture decorator removed in 9.x
@pytest.yield_fixture was an alias for @pytest.fixture. It was deprecated in 7.x and removed. Use @pytest.fixture with yield directly.

Basic fixture and parametrize usage. Run with: pytest -v

# test_example.py import pytest @pytest.fixture def sample_data(): return {"key": "value"} def test_basic(sample_data): assert sample_data["key"] == "value" @pytest.mark.parametrize("x,expected", [(1, 2), (2, 4)]) def test_double(x, expected): assert x * 2 == expected # Run: pytest -v
pytest --version
Debug
Known issues
breakingpytest.warns(None) removed in 8.0. It was used to assert no warnings were emitted, but its semantics were inverted — it actually asserted at least one warning was raised. This pattern is very common in LLM-generated test code.
fix
To assert no warnings: use warnings.catch_warnings() or recwarn fixture and assert len(recwarn) == 0. To assert a specific warning: pytest.warns(UserWarning).
affects: < 8.0
breaking@pytest.yield_fixture removed. LLMs frequently generate this decorator as it appeared in tutorials for years.
fix
Replace @pytest.yield_fixture with @pytest.fixture. yield inside @pytest.fixture has been supported since pytest 3.0.
affects: < 9.0
breakingnose plugin support removed in 8.0. Tests written for nose (using setup/teardown at module level, nose-style generators) will fail to collect.
fix
Rewrite nose-style tests using pytest fixtures and @pytest.mark.parametrize.
affects: < 8.0
breakingPython 3.9 support dropped in pytest 9.0 (following Python 3.9 EOL). Tests on Python 3.9 must pin to pytest<9.
fix
Pin pytest<9 for Python 3.9 environments.
affects: >= 9.0
breakingFile/directory collection order changed in pytest 8.x. Files and directories are now collected alphabetically together. Previously, files were collected before directories. Test suites with ordering assumptions may break.
fix
Do not rely on implicit test collection order. Use pytest-ordering if explicit order is needed.
affects: < 8.0
gotchaAsync tests require pytest-asyncio. pytest does not natively run async def test_ functions — they will appear to pass silently without actually running the test body.
fix
pip install pytest-asyncio. Add asyncio_mode = 'auto' to pytest.ini or mark individual tests with @pytest.mark.asyncio.
affects: all
gotcha--strict renamed to --strict-markers (for marker strictness) and --strict-config (for config strictness). The bare --strict still works in 9.x but now enables full strict mode.
fix
Use --strict-markers to fail on undeclared markers. Declare all markers in pytest.ini under [pytest] markers.
affects: all
gotchapytest_plugins defined in non-root conftest.py files is deprecated. It activates plugins globally, not just for tests below that conftest.
fix
Define pytest_plugins only in the root conftest.py or pyproject.toml.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest'
The 'pytest' package is not installed in the current Python environment.
fix
Install 'pytest' using pip: 'pip install pytest'.
ModuleNotFoundError: No module named 'pytest_sharding'
The 'pytest_sharding' plugin is not installed in the current Python environment.
fix
Install the 'pytest_sharding' plugin using pip: 'pip install pytest_sharding'.
ModuleNotFoundError: No module named 'my_module'
The module 'my_module' is not in the Python path, often due to incorrect project structure or missing '__init__.py' files.
fix
Ensure the module is in the Python path by adding '__init__.py' files to directories and adjusting the 'PYTHONPATH' environment variable if necessary.
ImportError: No module named 'app'
The 'app' module cannot be found, possibly due to incorrect import statements or missing '__init__.py' files.
fix
Verify the import statements are correct and that '__init__.py' files are present in the necessary directories.
pytest: command not found
The `pytest` executable is not found in your system's PATH, typically because it's not installed, or your virtual environment isn't activated, or the installation location isn't in PATH.
fix
First, ensure pytest is installed in your active Python environment: `pip install pytest`. If using a virtual environment, activate it (`source venv/bin/activate` on Linux/macOS, `venv\Scripts\activate` on Windows) before running `pytest`. Alternatively, you can always invoke it as a Python module: `python -m pytest`.
Upgrade
Version history
9.1.1latest on PyPI · released Jun 19, 2026
Audit
Dependencies
pytest-asynciooptionalRequired for async test functions. pytest does not natively run async tests.
pytest-covoptionalCoverage reporting integration.
pytest-xdistoptionalParallel test execution with -n flag.
Agent activity
19 hits · last 30 days
node
16
Resources