# AssertionError: assert 1 == 2
# passes with -p no:xdist, fails with -n auto

- **ID:** `python/pytest-xdist-shared-state`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Tests share global state (module-level caches, singletons, files) that is safe serially but races or persists across worker processes under pytest-xdist.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   @pytest.fixture(autouse=True)
def reset_state():
    myapp.cache.clear()
    yield
    myapp.cache.clear()
   ```
2. **** (88% success)
   ```
   def test_db(tmp_path, worker_id):
    if worker_id == 'master':
        db = tmp_path / 'db.sqlite'
    else:
        db = tmp_path / f'db_{worker_id}.sqlite'
    ...
   ```

## Dead Ends

- **** — Masks the race condition; reruns may pass by luck and hide real bugs, and flaky plugin adds overhead. (70% fail)
- **** — More workers means more contention, making the race more likely, not less. (95% fail)
- **** — Slows tests and does not eliminate the race; still fails intermittently on slow CI machines. (85% fail)
