Skip to content

Pytest fixture uninjected reference inspection

Pytest fixture uninjected reference inspection reports fixture names referenced in a test or fixture without being declared as parameters.

How to use it

Open a pytest function that uses a fixture name directly without injecting it.

When it helps

Use this inspection to catch accidental global-looking fixture references that pytest will not inject automatically.

Turn a function into a fixture

When a test requests an unknown fixture and the same file defines an undecorated, non-test function with that name, the warning offers BetterPy: Turn '' into pytest fixture. It adds @pytest.fixture (and import pytest when missing). The fix is offered only when no other code references the function, because calling a fixture directly fails at runtime.

Notes

  • BetterPy focuses on fixture functions and pytest test contexts.
  • The feature is gated by the Pytest fixture uninjected reference inspection setting under Settings | BetterPy | Testing (Pytest) | Fixture Inspections.