python
runtime_error
ai_generated
true
Failed: fixture 'client' not found in teardown
ID: python/pytest-fixure-teardown-error
80%Fix Rate
84%Confidence
0Evidence
2024-06-09First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
Root Cause
在 fixture 的 teardown 代码中尝试访问另一个不存在的 fixture
generic中文
在 fixture 的 teardown 代码中尝试访问另一个不存在的 fixture
Workarounds
-
90% success
@pytest.fixture def client(): yield create_client() # teardown code -
80% success
def client(request): c = create_client() request.addfinalizer(c.close) return c
Dead Ends
Common approaches that don't work:
-
80% fail
teardown 阶段不应创建新 fixture
-
60% fail
会导致资源泄漏