# ERROR at teardown of test_x
RuntimeError: generator didn't stop after throw()
During handling of the above exception, another exception occurred:
ValueError: I/O operation on closed file

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

## Root Cause

A generator-based fixture swallowed the GeneratorExit/exception in a bare except or a finally that raised, preventing proper teardown. pytest then reports teardown errors that mask the real test result.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Never catch BaseException or bare except in a yield fixture. Use try/finally:
  @pytest.fixture
  def res():
      r = acquire()
      try:
          yield r
      finally:
          r.close()
   ```
2. **** (90% success)
   ```
   Use addfinalizer for complex cleanup:
  @pytest.fixture
  def res(request):
      r = acquire()
      request.addfinalizer(r.close)
      return r
   ```

## Dead Ends

- **** — If the except swallows GeneratorExit, the 'generator didn't stop' error persists. (80% fail)
- **** — Loses cleanup; resources leak across tests. (70% fail)
