mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
Add pytest-xdist and run the backend test suite across multiple workers (`-n 4` in CI). Each worker gets its own database so the autouse `clear_database` fixture can't wipe rows another worker is mid-test with: - Rootdir `backend/conftest.py` sets a per-worker `DB_NAME` (`romm_test_gw0`, ...) before any app module is imported, so each worker's engine binds to its own database. - `tests/conftest.py` creates the per-worker database on demand (mariadb/ mysql and postgresql paths) just before migrations run. - The test user's grant is widened to `*.*` (setup.sql + CI) so it can `CREATE DATABASE` for the workers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
16 lines
783 B
Python
16 lines
783 B
Python
import os
|
|
|
|
# When running under pytest-xdist, give each worker its own database so the
|
|
# autouse `clear_database` fixture in one worker can't wipe rows another worker
|
|
# is mid-test with. This must run before any application module (config /
|
|
# database handlers) is imported, so the engine built at import time binds to
|
|
# the per-worker name. As the rootdir conftest, this file is imported before
|
|
# `tests/conftest.py` (which imports those modules).
|
|
#
|
|
# The Redis cache needs no equivalent handling: under pytest it is an in-process
|
|
# FakeRedis, so each worker process is already isolated.
|
|
_xdist_worker = os.environ.get("PYTEST_XDIST_WORKER")
|
|
if _xdist_worker:
|
|
_base_db_name = os.environ.get("DB_NAME", "romm_test")
|
|
os.environ["DB_NAME"] = f"{_base_db_name}_{_xdist_worker}"
|