Enable parallel test execution and mark slow Excel parsing tests#244
Enable parallel test execution and mark slow Excel parsing tests#244
Conversation
11af3fd to
f3d269b
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
This PR speeds up the Python test suite by enabling parallel execution via pytest-xdist and introducing a slow marker so expensive Excel parsing/integration tests can be skipped by default while remaining runnable on-demand.
Changes:
- Add
pytest-xdistand configure pytest to run tests in parallel (-n auto). - Default to skipping
@pytest.mark.slowtests via pytestaddopts. - Mark Excel/Office parsing (and related) tests as
slowand document updated pytest usage.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Adds default pytest options for parallelism and skipping slow tests; registers the slow marker. |
requirements.txt |
Adds pytest-xdist dependency. |
README.md |
Updates testing instructions to reflect parallel runs and slow selection. |
utils/sync/wire_rolls/tests/test_wire_offsets.py |
Marks Excel parsing parametrized test as slow. |
utils/sync/daqbooks/tests/test_parse_n2_offsets.py |
Marks N2 Excel parsing tests as slow. |
utils/sync/daqbooks/tests/test_parse_j1_offsets.py |
Marks J1 Excel parsing tests as slow. |
utils/sync/daqbooks/tests/test_parse.py |
Imports pytest and marks Excel parsing unit tests as slow. |
routes/daqbook_offsets/tests/test_daqbook_offsets_debug.py |
Marks debug sync test as slow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
Head branch was pushed to by a user without write access
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
efbb750 to
7690886
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 12 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -155,5 +170,15 @@ jobs: | |||
| python -m pip install --upgrade pip | |||
| pip install -r requirements.txt | |||
|
|
|||
| - name: Wait for PostgreSQL to be ready | |||
| run: | | |||
| until pg_isready -h localhost -p 5432 -U testuser; do | |||
| echo "Waiting for PostgreSQL..." | |||
| sleep 2 | |||
| done | |||
|
|
|||
| - name: Run migrations | |||
| run: python -m alembic upgrade head | |||
|
|
|||
| - name: Run tests | |||
| run: pytest -v | |||
| run: pytest -v -m 'slow or not slow' | |||
There was a problem hiding this comment.
The CI job provisions a Postgres service and runs alembic upgrade head, but the test suite’s postgres_container fixture (conftest.py) always starts a Testcontainers-managed Postgres and sets its own DATABASE_URL. That means the service + migration step here are likely unused while tests still incur per-xdist-worker container startup/migrations, which can be slow/flaky. Consider either (a) updating the fixture to reuse DATABASE_URL when provided (CI-managed Postgres), or (b) removing the service/migration steps from this job and letting Testcontainers be the single source of truth.
| """Create sample Excel (.xlsm) and CSV files used by tests if not present. | ||
|
|
||
| This avoids committing large binary fixtures and keeps unit tests hermetic. | ||
|
|
||
| Note: This fixture must be explicitly declared as a dependency by test fixtures | ||
| that need the Excel files (e.g., j1_test_file, k6_test_file). It is not autouse | ||
| to avoid overhead when running non-slow tests that don't need Excel files. |
There was a problem hiding this comment.
The fixture docstring says this avoids committing large binary fixtures, but this PR adds J1_0325.xlsm and K6_0824.xlsm under tests/data/. Either remove these committed binaries and rely on the generator, or update the docstring to reflect the new approach (and consider storing generated files under a temp directory to keep tests hermetic).
| @pytest.mark.slow | ||
| def test_n2_offsets_not_equal_to_temp(n2_test_file): |
There was a problem hiding this comment.
These N2 Excel tests are now marked slow, but the referenced fixture file utils/sync/daqbooks/tests/data/N2_1125.xlsm does not appear to exist in the repo, so the fixture will always skip and these tests won’t actually run (even in CI with -m 'slow or not slow'). Consider adding/generating the missing .xlsm test fixture (similar to the J1/K6 generator) or adjusting the tests to use an available fixture.
1c986b6 to
8119da3
Compare
- Add pytest-xdist to requirements.txt - Configure pytest to run tests in parallel by default (-n auto) - Skip slow tests by default with -m 'not slow' - Mark slow Excel parsing tests with @pytest.mark.slow - Update README with new test commands - Test execution time improved from 30.24s to 12.61s (58% faster) Co-authored-by: rhythmatician <75549255+rhythmatician@users.noreply.github.com>
Use clearer pytest -m 'slow or not slow' instead of -m "" Co-authored-by: rhythmatician <75549255+rhythmatician@users.noreply.github.com>
1. Update CI to run all tests including slow ones with -m 'slow or not slow' 2. Clarify README label from "Full test suite" to "Default/fast test suite" 3. Remove autouse=True from ensure_daqbook_test_fixtures to avoid overhead in non-slow test runs Co-authored-by: rhythmatician <75549255+rhythmatician@users.noreply.github.com>
Co-authored-by: rhythmatician <75549255+rhythmatician@users.noreply.github.com>
8119da3 to
f00540f
Compare
Test Suite Performance Improvement ✅
Summary
Successfully optimized test suite execution speed by implementing parallel test execution and marking slow tests for optional exclusion.
Performance Results
Changes Implemented
pytest-xdistto requirements.txt for parallel test execution-n autoto run tests in parallel using all available CPU cores-m 'not slow'to skip slow tests by default@pytest.mark.slowdecorator:test_run_refresh_daqbook_offsets_debug(6.73s setup time)pytest -v(default)pytest -v -m 'slow or not slow'pytest -v -m "slow"pytest -v -n 0PR Review Feedback Addressed
-m 'slow or not slow'autouse=Truefrom fixture to avoid overhead in non-slow test runsTesting & Verification
-m "slow"Security Summary
No security vulnerabilities found by CodeQL scanner.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.