python config_error ai_generated true

UsageError: @pytest.mark.usefixtures with unknown fixture 'nonexistent_fixture'

ID: python/pytest-mark-usefixtures-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-04-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.9 active
3.10 active

Root Cause

The fixture name specified in @pytest.mark.usefixtures does not exist in any conftest.py or test file.

generic

中文

在 @pytest.mark.usefixtures 中指定的夹具名称在任何 conftest.py 或测试文件中都不存在。

Workarounds

  1. 95% success Define the missing fixture in the test file or conftest.py.
    @pytest.fixture
    def nonexistent_fixture(): return 'value'
  2. 90% success Correct the fixture name to match an existing fixture.
    @pytest.mark.usefixtures('existing_fixture')

Dead Ends

Common approaches that don't work:

  1. Adding a fixture with the same name but wrong scope 60% fail

    The fixture must be defined and accessible; scope mismatch may still cause errors.

  2. Removing the usefixtures marker entirely 70% fail

    If the fixture is required for test setup, tests may fail due to missing dependencies.