# AssertionError: 2 != 3 during subTest (index=0)

- **ID:** `python/unittest-subtest-failure`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A subTest context manager failed due to an assertion error, indicating that one iteration of a looped test failed while others may pass.

## Version Compatibility

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

## Workarounds

1. **Debug the specific subTest iteration that fails** (90% success)
   ```
   for i, value in enumerate(data):
    with self.subTest(i=i):
        self.assertEqual(value, expected[i])
If it fails, check the value and expected at index i.
   ```
2. **Use a more descriptive subTest message to identify the failing case** (85% success)
   ```
   with self.subTest(i=i, value=value):
    self.assertEqual(value, expected[i])
This provides more context in the error message.
   ```

## Dead Ends

- **Removing the subTest context to run all iterations as separate tests** — This changes the test structure and may not capture the context of the failure. (50% fail)
- **Increasing the number of iterations to avoid the specific failing case** — This masks the bug; the failing case should be fixed. (80% fail)
