Skip to content

Add pytest-xdist for non-integration tests - #107

Open
iloveitaly wants to merge 2 commits into
masterfrom
cursor/pytest-xdist-support-950a
Open

iloveitaly wants to merge 2 commits into
masterfrom
cursor/pytest-xdist-support-950a

Conversation

@iloveitaly

Copy link
Copy Markdown
Owner

Motivation

Non-integration tests are independent enough to run in parallel, but the suite currently executes them serially. pytest-xdist should cut that wall-clock time, especially on CI.

A previous attempt (#61) rewrote worker database URLs after app was imported. app.setup() already binds Postgres and Redis at import time, so every worker still shared the main test database.

Integration tests stay serial: they share a live server, browser, and truncation-based DB reset.

Description

  • Add pytest-xdist and run non-integration tests with -n auto --dist loadgroup from just py_test.
  • Rewrite TEST_DATABASE_URL / TEST_REDIS_URL in each worker before any app import.
  • On the controller, truncate the template test DB, then CREATE DATABASE ... TEMPLATE one clone per worker (test_xdist_N).
  • Give Redis --databases 128 so workers can FLUSHDB without colliding (db 2+N).
  • Keep generated-file tests on a single worker via xdist_group.
  • Fail collection if xdist is combined with tests/integration.

Screenshots / Test

Non-integration tests: just py_test (xdist on). Integration tests remain a separate serial pytest invocation.

Links

Open in Web Open in Cursor 

Give each xdist worker its own Postgres database and Redis logical DB so
transactional tests can run concurrently. Integration tests stay serial.

Co-authored-by: mike <mike@mikebian.co>
@iloveitaly
iloveitaly marked this pull request as ready for review August 31, 2026 19:35
Co-authored-by: mike <mike@mikebian.co>
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.

2 participants