# ERROR at teardown of test_x
RuntimeError: generator didn't stop after throw()
# or: ERROR: test_x - Exception: teardown error swallowed

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

## Root Cause

A yield fixture's teardown raises an exception that masks the original test failure, or the generator is re-entered after yielding, causing pytest to report a teardown error.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   @pytest.fixture
def resource(request):
    r = acquire()
    request.addfinalizer(r.close)
    return r
   ```
2. **** (85% success)
   ```
   @pytest.fixture
def resource():
    r = acquire()
    yield r
    try:
        r.close()
    except Exception:
        import logging
        logging.exception('teardown failed')
        raise
   ```

## Dead Ends

- **** — Swallows real cleanup errors; resources may remain locked and subsequent tests fail. (75% fail)
- **** — Delays teardown to the end of the run but does not prevent the exception from masking failures. (60% fail)
