python config_error ai_generated true

未找到 fixture 'test_data'

fixture 'test_data' not found

ID: python/pytest-fixture-not-found

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-06-18首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

fixture 定义在 conftest.py 中,但该文件不在测试文件所在目录或其父目录中,或者 fixture 名称拼写错误。

English

The fixture is defined in a conftest.py file that is not in the same directory or a parent directory of the test file, or the fixture name is misspelled.

generic

解决方案

  1. 98% 成功率
    Create conftest.py in the test directory and define the fixture there.
  2. 90% 成功率
    Verify the fixture name and that it's defined at module level.

无效尝试

常见但无效的做法:

  1. 50% 失败

    If the fixture is needed by multiple tests in different files, it won't be available.

  2. 80% 失败

    Fixture names are case-sensitive and must match exactly.