# sqlite3.OperationalError: database is locked

- **ID:** `python/pytest-parallel-fixture-db-collision`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Multiple xdist workers share the same SQLite file (or the same fixture-created DB path) and contend for write locks.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   @pytest.fixture
def db(tmp_path, worker_id):
    path = tmp_path / f"test-{worker_id}.db"
    conn = sqlite3.connect(path)
    yield conn
    conn.close()
   ```
2. **** (90% success)
   ```
   # docker-compose with postgres
# pytest.ini
[pytest]
addopts = -n auto
# DATABASE_URL=postgresql://user:pass@localhost/test
   ```
3. **** (88% success)
   ```
   pytestmark = pytest.mark.xdist_group(name="db")
# run: pytest -n auto --dist=loadgroup
   ```

## Dead Ends

- **** — Reduces but does not eliminate lock contention under load. (70% fail)
- **** — Disables parallelism; CI time blows up. (60% fail)
- **** — Autocommit increases contention rather than reducing it. (85% fail)
