Matched signals
- ERROR at setup of
- ERROR at teardown of
- fixture not found
- fixture error
- ScopeMismatch
- could not import conftest
- ERROR collecting
- E fixture
pytest fixture setup or teardown failure
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.
Symptoms
Faultline looks for one or more of these log fragments:
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.
Why it matters
Fixture errors occur when a fixture dependency cannot be resolved, fixture scope is inconsistent, an external resource fails to initialize inside the fixture, or a generator fixture raises during teardown.
Prevention
- Keep fixtures that access external resources in a dedicated
conftest.pywith explicit scope annotations. - Run the suite with
--setup-showin CI when fixture debugging is needed. - Add a smoke fixture test that validates required external dependencies early.
Try it locally
pytest -x --setup-show tests/
pytest --co -q tests/
pytest -x --setup-show tests/
How Faultline detects it
Use faultline explain pytest-fixture-error to see the full playbook.
faultline analyze build.log
faultline explain pytest-fixture-error
Generated from playbooks/bundled/log/test/pytest-fixture-error.yaml. Do not edit directly.