{"id":197,"library":"pytest","title":"pytest","description":"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.","status":"active","version":"9.0.2","language":"python","source_language":"en","source_url":"https://docs.pytest.org/en/stable/changelog.html","tags":["testing","test-runner","fixtures","parametrize","python"],"install":[{"cmd":"pip install pytest","lang":"bash","label":"Python"},{"cmd":"pip install pytest pytest-cov pytest-asyncio","lang":"bash","label":"Common test stack"}],"dependencies":[{"reason":"Required for async test functions. pytest does not natively run async tests.","package":"pytest-asyncio","optional":true},{"reason":"Coverage reporting integration.","package":"pytest-cov","optional":true},{"reason":"Parallel test execution with -n flag.","package":"pytest-xdist","optional":true}],"imports":[{"note":"Always import as 'import pytest'. The py.test command name is legacy; use the pytest command.","wrong":"from py.test import *  # py.test CLI name only, not an importable package","symbol":"pytest","correct":"import pytest"},{"note":"@pytest.yield_fixture was an alias for @pytest.fixture. It was deprecated in 7.x and removed. Use @pytest.fixture with yield directly.","wrong":"@pytest.yield_fixture\ndef my_fixture():\n    yield value  # yield_fixture decorator removed in 9.x","symbol":"pytest.fixture","correct":"@pytest.fixture\ndef my_fixture(): ..."}],"quickstart":{"code":"# test_example.py\nimport pytest\n\n@pytest.fixture\ndef sample_data():\n    return {\"key\": \"value\"}\n\ndef test_basic(sample_data):\n    assert sample_data[\"key\"] == \"value\"\n\n@pytest.mark.parametrize(\"x,expected\", [(1, 2), (2, 4)])\ndef test_double(x, expected):\n    assert x * 2 == expected\n\n# Run: pytest -v","lang":"python","description":"Basic fixture and parametrize usage. Run with: pytest -v"},"warnings":[{"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).","message":"pytest.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.","severity":"breaking","affected_versions":"< 8.0"},{"fix":"Replace @pytest.yield_fixture with @pytest.fixture. yield inside @pytest.fixture has been supported since pytest 3.0.","message":"@pytest.yield_fixture removed. LLMs frequently generate this decorator as it appeared in tutorials for years.","severity":"breaking","affected_versions":"< 9.0"},{"fix":"Rewrite nose-style tests using pytest fixtures and @pytest.mark.parametrize.","message":"nose plugin support removed in 8.0. Tests written for nose (using setup/teardown at module level, nose-style generators) will fail to collect.","severity":"breaking","affected_versions":"< 8.0"},{"fix":"Pin pytest<9 for Python 3.9 environments.","message":"Python 3.9 support dropped in pytest 9.0 (following Python 3.9 EOL). Tests on Python 3.9 must pin to pytest<9.","severity":"breaking","affected_versions":">= 9.0"},{"fix":"Do not rely on implicit test collection order. Use pytest-ordering if explicit order is needed.","message":"File/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.","severity":"breaking","affected_versions":"< 8.0"},{"fix":"pip install pytest-asyncio. Add asyncio_mode = 'auto' to pytest.ini or mark individual tests with @pytest.mark.asyncio.","message":"Async 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Use --strict-markers to fail on undeclared markers. Declare all markers in pytest.ini under [pytest] markers.","message":"--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.","severity":"gotcha","affected_versions":"all"},{"fix":"Define pytest_plugins only in the root conftest.py or pyproject.toml.","message":"pytest_plugins defined in non-root conftest.py files is deprecated. It activates plugins globally, not just for tests below that conftest.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T10:01:48.989Z","next_check":"2026-06-25T00:00:00.000Z","problems":[{"fix":"Install 'pytest' using pip: 'pip install pytest'.","cause":"The 'pytest' package is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'pytest'"},{"fix":"Install the 'pytest_sharding' plugin using pip: 'pip install pytest_sharding'.","cause":"The 'pytest_sharding' plugin is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'pytest_sharding'"},{"fix":"Ensure the module is in the Python path by adding '__init__.py' files to directories and adjusting the 'PYTHONPATH' environment variable if necessary.","cause":"The module 'my_module' is not in the Python path, often due to incorrect project structure or missing '__init__.py' files.","error":"ModuleNotFoundError: No module named 'my_module'"},{"fix":"Verify the import statements are correct and that '__init__.py' files are present in the necessary directories.","cause":"The 'app' module cannot be found, possibly due to incorrect import statements or missing '__init__.py' files.","error":"ImportError: No module named 'app'"},{"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`.","cause":"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.","error":"pytest: command not found"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.46,"mem_mb":12.2,"disk_size":"30.4M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.43,"mem_mb":12.2,"disk_size":"32.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.29,"mem_mb":12.2,"disk_size":"31M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.29,"mem_mb":12.2,"disk_size":"33M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.58,"mem_mb":12.9,"disk_size":"33.3M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.61,"mem_mb":12.9,"disk_size":"35.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.47,"mem_mb":12.9,"disk_size":"34M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.47,"mem_mb":12.9,"disk_size":"36M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.53,"mem_mb":12.8,"disk_size":"24.9M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.52,"mem_mb":12.8,"disk_size":"27.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.51,"mem_mb":12.8,"disk_size":"25M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.56,"mem_mb":12.8,"disk_size":"28M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.47,"mem_mb":11.8,"disk_size":"24.6M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.46,"mem_mb":11.8,"disk_size":"26.5M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.43,"mem_mb":11.8,"disk_size":"25M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.44,"mem_mb":11.8,"disk_size":"27M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.37,"mem_mb":11.2,"disk_size":"29.7M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.36,"mem_mb":11.2,"disk_size":"31.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.34,"mem_mb":11.2,"disk_size":"30M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.34,"mem_mb":11.2,"disk_size":"32M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}