# sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked

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

## Root Cause

Multiple pytest-xdist workers share the same SQLite file; concurrent writes cause lock contention and OperationalError.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   @pytest.fixture(scope='session')
def db_url(tmp_path_factory, worker_id):
    if worker_id == 'master':
        path = tmp_path_factory.mktemp('db') / 'test.db'
    else:
        path = tmp_path_factory.mktemp(f'db_{worker_id}') / 'test.db'
    return f'sqlite:///{path}'
   ```
2. **** (92% success)
   ```
   # docker-compose.yml provides postgres
# conftest.py
@pytest.fixture(scope='session')
def db_url(worker_id):
    return f'postgresql://test:test@localhost/test_{worker_id}'
   ```

## Dead Ends

- **** — Reduces frequency but not correctness; long-running transactions still deadlock and CI slows down. (70% fail)
- **** — Defeats the purpose of parallel tests; CI time returns to serial levels. (90% fail)
- **** — WAL helps readers but writers still serialize; contention remains under heavy xdist load. (75% fail)
