# ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/test.log' mode='w' encoding='UTF-8'>

- **ID:** `python/unittest-teardown-not-called-on-skip`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A test calls self.skipTest() inside setUp after opening a resource, so tearDown never runs and the resource leaks; or setUpClass raised and tearDownClass is skipped.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   class TestX(unittest.TestCase):
    def setUp(self):
        self.f = open('/tmp/test.log', 'w')
        self.addCleanup(self.f.close)
        if not condition:
            self.skipTest('condition not met')
   ```
2. **** (92% success)
   ```
   def test_x(self):
    with open('/tmp/test.log', 'w') as f:
        ...
    # file closed even if test fails
   ```

## Dead Ends

- **** — Hides the leak; file descriptors accumulate across a large test suite and eventually cause EMFILE. (80% fail)
- **** — Skips before any setup runs, but other tests that do open resources still leak. (60% fail)
