# AssertionError: Test case order mismatch: expected test_second after test_first

- **ID:** `python/unittest-testcase-order-error`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Tests that rely on execution order (e.g., shared state) fail when unittest runs tests in alphabetical order by default.

## Version Compatibility

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

## Workarounds

1. **Use pytest with pytest-ordering plugin to specify test order explicitly.** (85% success)
   ```
   Install pytest-ordering and use @pytest.mark.run(order=1) decorators.
   ```
2. **Refactor tests to be independent and not rely on order.** (90% success)
   ```
   Use setUp to initialize state for each test individually.
   ```

## Dead Ends

- **Renaming test methods to ensure alphabetical order** — This is fragile and may break if new tests are added with different names. (70% fail)
- **Using a global variable to track state across tests** — Shared state can lead to flaky tests and is against testing best practices. (80% fail)
