Skip to content

Speedup tests - #696

Open
varmar05 wants to merge 3 commits into
developfrom
speedup-tests
Open

varmar05 wants to merge 3 commits into
developfrom
speedup-tests

Conversation

@varmar05

@varmar05 varmar05 commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Issue

The test suite spent most of its time on per-test setup, not on the tests themselves: every test built a new Flask app, created and dropped all tables, and hashed passwords with production bcrypt cost. This PR removes that overhead and allows running tests in parallel.

Changes

  • Lower bcrypt cost in tests: BCRYPT_LOG_ROUNDS=4 (the minimum) in .test.env. Cost 12 took ~0.4 s per hash or check, at least twice per test.
  • One app and schema per test session: session_app creates the app and tables once. Each test gets a fresh app context and an empty database; clean_db() deletes all rows and restarts sequences (~15 ms, against ~160 ms for TRUNCATE).
  • Config changes in tests use monkeypatch, so they are undone after each test instead of leaking into later ones.
  • Parallel runs with pytest-xdist: a root conftest.py gives each worker its own database (<DB_DATABASE>_gw<N>, created automatically by create_db()) and its own temporary directories. CI runs with -n auto.

Results (local, 385 tests)

time
before ~5–6 min
serial ~51 s
-n 4 ~19 s

All tests pass in normal, reverse and several random orders.

In CI it seems 15 min -> 2 min.

varmar05 and others added 3 commits October 8, 2026 16:06
- create flask app and db tables once per session, each test gets fresh
  app context and empty tables (clean_db deletes rows and restarts sequences)
- use monkeypatch for config changes in tests so they do not leak
- fix tests relying on undefined order of db rows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each xdist worker uses its own database (created automatically) and temporary directories.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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