Skip to content
Latchkey

pytest "fixture not found" in CI

A test function named a fixture in its arguments, but pytest found no fixture by that name in scope. The fixture may live in a conftest that does not apply, come from an uninstalled plugin, or be misspelled.

What this error means

pytest errors with "fixture 'db_session' not found" and lists the fixtures it does know about, suggesting close matches.

pytest
E       fixture 'db_session' not found
>       available fixtures: cache, capfd, capsys, monkeypatch, tmp_path, ...
>       use 'pytest --fixtures [testpath]' for help on them.

Common causes

The fixture is defined in an out-of-scope conftest

A fixture in a conftest.py that does not cover the test's directory is not visible to it.

A plugin providing the fixture is not installed

Fixtures like db_session may come from a pytest plugin missing in the CI environment.

How to fix it

Place the fixture where tests can see it

  1. Move shared fixtures into a conftest.py at or above the test directory.
  2. Or install the plugin that provides the fixture.
  3. Run pytest --fixtures to confirm it is now discoverable.
Terminal
pytest --fixtures tests/

Install the fixture-providing plugin

Add the plugin to your dev dependencies so its fixtures register.

Terminal
pip install pytest-postgresql

How to prevent it

  • Keep shared fixtures in a top-level conftest.py.
  • Install all pytest plugins your tests rely on in CI.
  • Use pytest --fixtures to audit available fixtures.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →