Drastically reduced number and run time of integration tests - #1142
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR refactors HSSM’s integration test suite to reduce runtime and duplication by replacing large Cartesian-product parameter grids with smaller pairwise covering arrays, while also tightening a prior-construction error into a proper runtime exception and updating tooling configuration.
Changes:
- Reworked multiple integration test matrices (MCMC, VI, choice-only, missing-data/deadline) from full grids into pairwise covering arrays; merged deadline + missing-data test files where behavior is controlled by a single mechanism flag.
- Changed
Priorto raiseValueError(instead of relying onassert) whenboundsand a customdistare provided together; updated unit test expectations accordingly. - Updated pyrefly versions/config and simplified slow-test workflow wiring.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/unit/test_prior.py |
Updates expected exception type for invalid Prior(bounds=..., dist=...) usage. |
tests/unit/likelihoods/test_likelihoods.py |
Fixes ONNX fixture path resolution to point at tests/fixtures. |
tests/integration/test_vi.py |
Replaces large VI grid with pairwise covering array; splits out blackbox rejection tests. |
tests/integration/test_missing_data_vi.py |
Merges missing-data and deadline VI coverage; switches to pairwise matrix + deterministic data injection. |
tests/integration/test_missing_data_mcmc.py |
Merges missing-data + deadline MCMC tests; replaces full grid with pairwise matrix + explicit rejected-combo tests. |
tests/integration/test_missing_data_and_deadline_vi.py |
Removes now-redundant deadline VI integration file (merged elsewhere). |
tests/integration/test_missing_data_and_deadline_mcmc.py |
Removes now-redundant deadline MCMC integration file (merged elsewhere). |
tests/integration/test_mcmc.py |
Replaces full sampler/likelihood/shape cross with pairwise coverage; adds default-sampler resolution test. |
tests/integration/test_choice_only.py |
Shrinks choice-only integration matrix via pairwise coverage; keeps analytical+jax path coverage. |
src/hssm/prior.py |
Converts bounds+dist conflict from assert to ValueError; adds/adjusts type annotations. |
pyproject.toml |
Bumps dev dependency requirement for pyrefly to >=1.2.0. |
.pre-commit-config.yaml |
Updates pyrefly hook rev to 1.2.0 and modifies hook configuration. |
.github/workflows/run_tests.yml |
Removes support for custom pytest args and simplifies test invocation. |
.github/workflows/run_slow_tests.yml |
Refactors slow-test workflow to delegate to run_tests.yml. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
tests/integration/test_missing_data_mcmc.py (1)
178-196: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
matchreceives an unescaped literal message.
pytest.raises(match=...)treats the string as a regular expression. The pattern works here only because.matches any character. Wrap the expected text inre.escapeso future edits to the message stay reliable.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/test_missing_data_mcmc.py` around lines 178 - 196, Update test_deadline_requires_missing_data to pass the expected ValueError message through re.escape before supplying it to pytest.raises(match=...), and add the required re import if absent. Preserve the existing message text and exception assertion.tests/integration/test_choice_only.py (1)
89-108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
sampleis duplicated across the integration suites with a different return contract.This copy returns the sampling result. The copies in
tests/integration/test_mcmc.py(Line 72) andtests/integration/test_missing_data_mcmc.py(Line 88) returnNone. Move one helper into a shared module, such astests/integration/conftest.py, and always returnmodel.sample(...). This removes three near-identical bodies and one silent behavior difference. See the consolidated comment for the full set of duplicated helpers.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/test_choice_only.py` around lines 89 - 108, Move the duplicated sample helper into the shared integration conftest module, preserving its slice-specific step configuration and sampling arguments. Update test_mcmc.py, test_missing_data_mcmc.py, and test_choice_only.py to reuse this helper, and ensure every path returns model.sample(...) consistently.tests/integration/test_mcmc.py (1)
232-303: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winThe post-processing tests share one fit and depend on figure state.
Each test calls
az.plot_trace_distseveral times and then readsplt.gcf(). The figure count assertions pass only if no earlier figure remains current. Close figures between the assertions to keep the tests independent of the matplotlib global state.♻️ Proposed cleanup for `test_post_processing_reg_v_a`
az.plot_trace_dist(model.traces) fig = plt.gcf() assert len(fig.axes) // 2 == 8 + plt.close("all") az.plot_trace_dist(model.traces, var_names=["~a"]) fig = plt.gcf() assert len(fig.axes) // 2 == 8 + plt.close("all")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/test_mcmc.py` around lines 232 - 303, Update the plotting assertions in test_post_processing_simple, test_post_processing_reg, and test_post_processing_reg_v_a to close each generated matplotlib figure after inspecting it, including between repeated az.plot_trace_dist calls. Ensure figure cleanup prevents plt.gcf() from observing stale figures and keeps the tests independent of global matplotlib state.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/integration/test_missing_data_mcmc.py`:
- Around line 59-69: Update prepare_data to normalize missing_indices into a
boolean NumPy mask for both modes, converting the random index selection in the
non-"opn" branch accordingly. Replace positional iloc assignment with
label-based data.loc[missing_mask, "rt"] assignment, preserving the existing
missing-value marker and avoiding dependence on column order.
---
Nitpick comments:
In `@tests/integration/test_choice_only.py`:
- Around line 89-108: Move the duplicated sample helper into the shared
integration conftest module, preserving its slice-specific step configuration
and sampling arguments. Update test_mcmc.py, test_missing_data_mcmc.py, and
test_choice_only.py to reuse this helper, and ensure every path returns
model.sample(...) consistently.
In `@tests/integration/test_mcmc.py`:
- Around line 232-303: Update the plotting assertions in
test_post_processing_simple, test_post_processing_reg, and
test_post_processing_reg_v_a to close each generated matplotlib figure after
inspecting it, including between repeated az.plot_trace_dist calls. Ensure
figure cleanup prevents plt.gcf() from observing stale figures and keeps the
tests independent of global matplotlib state.
In `@tests/integration/test_missing_data_mcmc.py`:
- Around line 178-196: Update test_deadline_requires_missing_data to pass the
expected ValueError message through re.escape before supplying it to
pytest.raises(match=...), and add the required re import if absent. Preserve the
existing message text and exception assertion.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9ff15e31-effe-4df8-9726-b6f3782b7615
📒 Files selected for processing (14)
.github/workflows/run_slow_tests.yml.github/workflows/run_tests.yml.pre-commit-config.yamlpyproject.tomlsrc/hssm/prior.pytests/integration/test_choice_only.pytests/integration/test_mcmc.pytests/integration/test_missing_data_and_deadline_mcmc.pytests/integration/test_missing_data_and_deadline_vi.pytests/integration/test_missing_data_mcmc.pytests/integration/test_missing_data_vi.pytests/integration/test_vi.pytests/unit/likelihoods/test_likelihoods.pytests/unit/test_prior.py
💤 Files with no reviewable changes (2)
- tests/integration/test_missing_data_and_deadline_mcmc.py
- tests/integration/test_missing_data_and_deadline_vi.py
|
Heads-up on a merge-order collision with #1143 (scheduled drift detection) — flagging early since whichever of us merges second breaks the other, and both breakages are silent rather than loud. #1143 adds a 1. fast:
uses: ./.github/workflows/run_tests.yml
with:
test_args: "-o addopts= --timeout=360"After this PR, Three ways out, your call: keep a narrow 2. The slow suite becomes unreachable from a scheduled run. if: >-
github.event_name == 'workflow_dispatch' ||
contains(github.event.head_commit.message, '[run slow]')The The clean fix given this PR's own design is for Suggested order: merge this first, then I rebase #1143 onto it and adapt both jobs in one commit. If you'd rather I go first, say so and I'll instead add the drift-facing bits here as a follow-up. Worth noting the safety net worked as designed while I was checking this: even if the slow job silently skipped, the spine's |
test_missing_data_and_deadline.py to reduce number of tests and repetitions
test_missing_data_and_deadline_vi.py to reduce number of tests and repetitions
converage workflow
cb29c1b to
a0491fe
Compare
This PR reduces the number of integration tests by using smart combinations to maintain coverage and pruning unnecessary tests
Summary by CodeRabbit
Bug Fixes
ValueError.Tests