# ERROR at teardown of test_example

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

## Root Cause

The teardown phase of a fixture or test raised an exception. This often happens when cleanup code (closing connections, deleting files) fails due to prior test failures or resource leaks.

## Version Compatibility

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

## Workarounds

1. **** (85% success)
   ```
   @pytest.fixture
def resource():
    r = acquire()
    yield r
    try:
        r.release()
    except Exception as e:
        logging.warning(f'Teardown failed: {e}')
   ```
2. **** (88% success)
   ```
   @pytest.fixture
def resource(request):
    r = acquire()
    def cleanup():
        try:
            r.release()
        except Exception:
            pass
    request.addfinalizer(cleanup)
    return r
   ```

## Dead Ends

- **** — This flag only affects collection errors, not teardown errors. The teardown failure will still be reported. (90% fail)
- **** — This leaves resources open, causing cascading failures in subsequent tests (e.g., database locks, port conflicts). (95% fail)
