pytest fixture setup or teardown failure
April 30, 2026 ยท View on GitHub
Playbook ID: pytest-fixture-error
Category: test
Severity: medium
Tags: pytest, python, fixture, setup, teardown, conftest
What this failure means
A pytest fixture failed during setup or teardown, causing the associated test to be marked as ERROR rather than FAILED. The test body never ran, or cleanup after the test raised an exception.
Common log signals
ERROR at setup of
ERROR at teardown of
fixture not found
fixture error
ScopeMismatch
could not import conftest
ERROR collecting
E fixture
Diagnosis
A pytest fixture failed during setup or teardown, causing the associated test to be marked as ERROR rather than FAILED. The test body never ran, or cleanup after the test raised an exception.
Fix steps
- Read the full
ERROR at setup of <test_name>traceback. The relevant line is usually in the fixture body, not the test. - For
fixture not found, check the fixture name spelling and confirm it is defined inconftest.pyor imported in the same module. - For
ScopeMismatch, widen the dependent fixture scope or pass the needed value directly. - Reproduce fixture setup locally with
pytest -x --setup-show tests/path/to_test.py. - For teardown failures, make sure
yieldfixtures wrap cleanup intry/finally.
Validation
pytest -x --setup-show tests/completes without the original fixture error.pytest --co -q tests/confirms pytest can still collect the expected suite.
Likely files to inspect
conftest.pytests/conftest.pypytest.inipyproject.toml
Run Faultline
faultline analyze build.log
faultline explain pytest-fixture-error
faultline workflow build.log --json --mode agent
Search phrases this page answers
- pytest fixture setup or teardown failure
- Test: pytest fixture setup or teardown failure
- PytestWarning: PytestUnraisableExceptionWarning
- faultline explain pytest-fixture-error
- Python pytest fixture setup or teardown failure
Generated from playbooks/bundled/log/test/pytest-fixture-error.yaml. Do not edit directly โ run make docs-generate.