# ERROR: test_foo (tests.test_x.TestCase.test_foo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "...", line N, in tearDown
    self.conn.close()
AttributeError: 'NoneType' object has no attribute 'close'

- **ID:** `python/unittest-teardown-exception-masked`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

tearDown runs even when setUp failed, so resources are None; the teardown exception replaces the original test error, obscuring the real failure.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   def setUp(self):
    self.conn = create_conn()
    self.addCleanup(self.conn.close)

# If create_conn raises, addCleanup is never registered, so tearDown does nothing
   ```
2. **** (85% success)
   ```
   def tearDown(self):
    conn = getattr(self, 'conn', None)
    if conn is not None:
        conn.close()
   ```

## Dead Ends

- **** — Silences real teardown errors and leaks resources, causing cascading failures in later tests. (90% fail)
- **** — Resources (DB connections, temp files) leak between tests, causing flakiness and cross-test pollution. (85% fail)
- **** — Symptom-level fix; the underlying setUp failure still hides behind the teardown error path. (60% fail)
