# AttributeError: 'TestCase' object has no attribute 'subTest'

- **ID:** `python/unittest-subtest-attribute-error`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

subTest was added in Python 3.4; running on an older interpreter, or the test class inherits from a custom base that shadows TestCase without calling super().__init__.

## Version Compatibility

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

## Workarounds

1. **** (93% success)
   ```
   # ensure base class calls super:
class Base(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

# then subTest works
with self.subTest(i=i):
    self.assertEqual(f(i), i)
   ```
2. **** (95% success)
   ```
   import pytest

@pytest.mark.parametrize('i', range(10))
def test_f(i):
    assert f(i) == i
   ```

## Dead Ends

- **** — Stops at the first failure; loses the ability to report all subtest failures. (50% fail)
- **** — Subtest failures are silently swallowed, so tests pass falsely. (90% fail)
