# E   RuntimeError: database connection still open after teardown
E   ERROR at teardown of test_create_user

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

## Root Cause

A fixture's teardown code raised an exception, often because the resource was already closed or the test left it in an inconsistent state.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Guard teardown with a check:
@pytest.fixture
def db():
    conn = connect()
    yield conn
    if not conn.closed:
        conn.close()
   ```
2. **** (85% success)
   ```
   Use `addfinalizer` for ordered cleanup:
@pytest.fixture
def resource(request):
    r = acquire()
    request.addfinalizer(r.release)
    return r
   ```

## Dead Ends

- **** — Leaks connections and causes cascading failures in later tests. (75% fail)
- **** — Hides real resource leaks and makes debugging harder. (65% fail)
