pytest fixture setup or teardown failure

A pytest fixture failed during setup or teardown, causing the associated test to be marked as `ERROR` rather than `FAILED`.

pytest-fixture-error medium confidence test python

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

  1. Read the full ERROR at setup of <test_name> traceback. The relevant line is usually in the fixture body, not the test.
  2. For fixture not found, check the fixture name spelling and confirm it is defined in conftest.py or imported in the same module.
  3. For ScopeMismatch, widen the dependent fixture scope or pass the needed value directly.
  4. Reproduce fixture setup locally with pytest -x --setup-show tests/path/to_test.py.
  5. For teardown failures, make sure yield fixtures wrap cleanup in try/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.py with explicit scope annotations.
  • Run the suite with --setup-show in 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.

Try it on your own failed log

$ faultline analyze failed.log
Want this across every CI run? Faultline Teams tracks recurring failures across all your repos and surfaces patterns in a shared dashboard.