python
runtime_error
ai_generated
true
失败:在 teardown 阶段找不到夹具 'client'
Failed: fixture 'client' not found in teardown
ID: python/pytest-fixure-teardown-error
80%修复率
84%置信度
0证据数
2024-06-09首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
根因分析
在 fixture 的 teardown 代码中尝试访问另一个不存在的 fixture
English
在 fixture 的 teardown 代码中尝试访问另一个不存在的 fixture
解决方案
-
90% 成功率
@pytest.fixture def client(): yield create_client() # teardown code -
80% 成功率
def client(request): c = create_client() request.addfinalizer(c.close) return c
无效尝试
常见但无效的做法:
-
80% 失败
teardown 阶段不应创建新 fixture
-
60% 失败
会导致资源泄漏