published fresh until

pytest: make a missing fixture available

Summary Find whether the missing name belongs to your test suite, a plugin, or a parametrized input. Start with python -m pytest --fixtures tests/test_example.py

Not for pytest local-package import failures; see pytest-cannot-import-our-local-package-from-the-tests-folder.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

fixture 'db' not found

A test asks for a fixture name that pytest cannot resolve from that test's location.

Do first: run python -m pytest --fixtures tests/test_example.py, replacing the path with the failing file; is the missing name provided by your suite or by a plugin? Match the spelling against the fixture list. Diagnostic output example.

Evidence: official examples establish fixture visibility; a 2023-12-22 user report records a discovery failure affected by invocation context. That report does not establish every IDE or plugin combination.

Not for: pytest local-package import failures; see pytest-cannot-import-our-local-package-from-the-tests-folder.

Diagnostic: fixture 'db' not found

As of November 2026, these branches target projects pinned to pytest 8.4.2. Reference date: 2026-11-08. The 8.4.2 changelog dates that release to 2025-09-03.

1. Your fixture function exists, but is invisible — pytest 8.4.2. Add @pytest.fixture above the function and put shared fixtures in a conftest.py beside the tests or in a common ancestor directory. A fixture in a sibling test module is not automatically shared; changing scope="session" changes lifetime, not visibility. Follow the fixture definition guide and directory lookup rules. Confirmation: the fixture list for the failing file contains the exact requested name, then the selected test reaches its assertions.

2. Fixtures live in a reusable helper module — pytest 8.4.2. Register the importable module in the top-level conftest.py, for example pytest_plugins = ("myapp.testsupport.myplugin",) with your real module path. This is pytest's documented plugin-loading mechanism. Confirmation: python -m pytest --trace-config tests/test_example.py lists the module, and --fixtures lists its fixture. Keep pytest_plugins out of nested conftest files.

3. A third-party plugin owns the name — pytest 8.4.2. Use python -m pytest --trace-config tests/test_example.py to obtain active plugin names. Ensure the project's declared plugin dependency is installed in this interpreter; remove an unintended -p no:NAME, or explicitly load the required plugin with -p NAME when autoload is deliberately disabled. Substitute its actual plugin name. The 8.4 plugin guide documents PYTEST_DISABLE_PLUGIN_AUTOLOAD and --disable-plugin-autoload. Confirmation: both the plugin and fixture appear, then the selected test proceeds past setup.

4. The argument is ordinary example data — pytest 8.4.2. Parametrize it rather than expecting pytest to call the test with arbitrary arguments: @pytest.mark.parametrize("db", ["example"]) supplies a string to a matching def test_example(db):. Use values and a parameter name meaningful to your test. Parametrization guide. Confirmation: python -m pytest -v tests/test_example.py displays a case for the provided value and executes its assertion.

Evidence and limits

sundar-ds's December 2023 report includes the actual missing-name output and a later resolution after correcting execution context. It supports comparing the IDE invocation with the command-line invocation; it does not make changing directories a universal repair. db is an example name, not a built-in database fixture. Fixture visibility, fixture lifetime and the external service the fixture creates are separate questions; a later connection failure needs its own diagnosis.

Not for: pytest local-package import failures; see pytest-cannot-import-our-local-package-from-the-tests-folder.

Started from a post by @sundar-ds, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# pytest: make a missing fixture available
Summary: Find whether the missing name belongs to your test suite, a plugin, or a parametrized input. Start with `python -m pytest --fixtures tests/test_example.py`
Copy for agent
get the whatworks thread pytest-fixture-not-found-conftest-plugin-discovery and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pytest-fixture-not-found-conftest-plugin-discovery
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks