Skip to content

fix(tests): read correct pytest-xdist worker env var - #323

Open
acailic wants to merge 1 commit into
mainfrom
fix/pytest-xdist-worker-env-var
Open

acailic wants to merge 1 commit into
mainfrom
fix/pytest-xdist-worker-env-var

Conversation

@acailic

@acailic acailic commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • tests/conftest.py read PYTEST_XDIST_WORKER_ID to name each xdist worker's isolated SQLite temp DB file, but pytest-xdist actually sets PYTEST_XDIST_WORKER (e.g. gw0) — confirmed by reading xdist/remote.py. The wrong name always fell back to "master", so every worker's DB filename was identical even though isolation itself wasn't broken (each worker still gets its own tempfile.mkdtemp() directory).

Context: this does NOT fix the CI flake blocking the auto-work queue

While investigating issue #311 (which has 10+ closed/duplicate PRs, all failing CI), I found that the Run tests with coverage CI step is broken on main itself — not just on PRs. Repro:

python3 -m pytest -q -n auto --timeout=30 --maxfail=5 --cov --cov-fail-under=70 -k "not integration"

fails non-deterministically with sqlalchemy.exc.OperationalError: unable to open database file / no such table: sessions, always in API route test files that share the process-lifetime app_context.engine/app_context.async_session_maker singletons.

I tested two hypotheses:

  1. This env var name bug (this PR) — confirmed real, but doesn't resolve the flake on its own.
  2. Switching the SQLite engine to NullPool (to rule out aiosqlite connections bound to a stale pytest-asyncio per-test event loop) — also did not resolve it.

Filing a separate issue with full repro notes and both ruled-out hypotheses so the next session doesn't repeat this investigation from scratch.

Test plan

  • ruff check . — all checks passed
  • python3 -m pytest -q -m 'not e2e' — 3171 passed, 34 skipped, 46 deselected

conftest.py read PYTEST_XDIST_WORKER_ID to name each xdist worker's
isolated SQLite file, but xdist actually sets PYTEST_XDIST_WORKER
(e.g. "gw0"). The wrong name always fell back to "master", so every
worker's DB file was labeled identically even though each worker still
gets its own tempfile.mkdtemp() directory (isolation was not broken,
but per-worker DB files were indistinguishable when debugging).

Verified in isolation this does not fully explain the "Run tests with
coverage" flake seen on main and on PRs (sqlalchemy.exc.OperationalError:
unable to open database file / no such table under `-n auto`) — that
flake persists after this fix and is tracked separately.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant