Repository navigation
Speedup tests - #696
Open
varmar05 wants to merge 3 commits into
Open
Speedup tests#696varmar05 wants to merge 3 commits into
varmar05 wants to merge 3 commits into
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
BCRYPT_LOG_ROUNDS=4(the minimum) in.test.env. Cost 12 took ~0.4 s per hash or check, at least twice per test.session_appcreates 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).monkeypatch, so they are undone after each test instead of leaking into later ones.conftest.pygives each worker its own database (<DB_DATABASE>_gw<N>, created automatically bycreate_db()) and its own temporary directories. CI runs with-n auto.Results (local, 385 tests)
-n 4All tests pass in normal, reverse and several random orders.
In CI it seems 15 min -> 2 min.