# RuntimeError: Error during teardown of fixture 'database' (got exception: OperationalError: database is locked)

- **ID:** `python/pytest-fixture-finalizer-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Ensure all database transactions are committed or rolled back before teardown: `yield db; db.close()`
   ```
2. **** (95% success)
   ```
   Use a context manager for the database connection to guarantee proper cleanup.
   ```

## Dead Ends

- **** — This is unreliable; the lock might persist longer, and sleeping wastes time. (70% fail)
- **** — This hides potential resource leaks and can cause issues in subsequent tests. (85% fail)
