python config_error ai_generated true

夹具查找错误:在可用夹具中找不到 'db',可用夹具包括 tmpdir、capsys

FixtureLookupError: fixture 'db' not found in available fixtures: ['tmpdir', 'capsys']

ID: python/pytest-fixure-order-error

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

版本兼容性

版本状态引入弃用备注
7.4.0 active

根因分析

测试函数引用了未定义的 fixture 名称

English

测试函数引用了未定义的 fixture 名称

generic

解决方案

  1. 95% 成功率
    @pytest.fixture
    def db(): ...
  2. 85% 成功率
    确保 fixture 名称一致

无效尝试

常见但无效的做法:

  1. 40% 失败

    可能与其他 fixture 冲突

  2. 90% 失败

    pytest 不支持该参数