python
runtime_error
ai_generated
true
RuntimeError: Error during teardown of fixture 'database' (got exception: OperationalError: database is locked)
ID: python/pytest-fixture-finalizer-error
80%Fix Rate
85%Confidence
0Evidence
2024-12-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
The fixture's finalizer (teardown) raises an exception, often because the database connection is still in use or locked when trying to close it.
generic中文
fixture 的 finalizer(teardown)抛出异常,通常是因为在尝试关闭数据库连接时,连接仍在使用中或被锁定。
Workarounds
-
90% success
Ensure all database transactions are committed or rolled back before teardown: `yield db; db.close()`
-
95% success
Use a context manager for the database connection to guarantee proper cleanup.
Dead Ends
Common approaches that don't work:
-
70% fail
This is unreliable; the lock might persist longer, and sleeping wastes time.
-
85% fail
This hides potential resource leaks and can cause issues in subsequent tests.