[PR #1608] [MERGED] fix(mlsysim): skip viz test when matplotlib is not installed #9219

Closed
opened 2026-05-03 01:29:13 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/harvard-edge/cs249r_book/pull/1608
Author: @Shashank-Tripathi-07
Created: 4/30/2026
Status: Merged
Merged: 4/30/2026
Merged by: @profvjreddi

Base: devHead: fix/mlsysim-viz-test-missing-skip


📝 Commits (2)

  • b464692 fix(mlsysim): skip viz test when matplotlib is not installed
  • 7125cb0 Merge branch 'dev' into fix/mlsysim-viz-test-missing-skip

📊 Changes

1 file changed (+2 additions, -0 deletions)

View changed files

📝 mlsysim/tests/test_evaluation_contract.py (+2 -0)

📄 Description

Summary

test_scorecard_plot_accepts_scenario_evaluation_quantities called plot_evaluation_scorecard unconditionally, but matplotlib is an optional dependency under mlsysim[viz] -- not installed in the base dev environment. Running pytest without the viz extra caused a hard ImportError instead of a graceful skip:

mlsysim/viz/plots.py:34: ImportError: matplotlib is required for plot generation.
FAILED tests/test_evaluation_contract.py::test_scorecard_plot_accepts_scenario_evaluation_quantities

Fix: Add pytest.importorskip("matplotlib") at the start of the test, which is the standard pytest pattern for optional-dependency tests -- the test is skipped when matplotlib is absent and runs normally when mlsysim[viz] is installed.

Before / after

# Before (base dev env, no matplotlib):
FAILED test_evaluation_contract.py::test_scorecard_plot_accepts_scenario_evaluation_quantities

# After:
385 passed, 3 skipped in 1.92s

Test plan

  • uv run python -m pytest tests/ with base deps -- confirm test is skipped, not failed
  • uv run python -m pytest tests/ --extras viz (or with matplotlib installed) -- confirm test runs and passes

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1608 **Author:** [@Shashank-Tripathi-07](https://github.com/Shashank-Tripathi-07) **Created:** 4/30/2026 **Status:** ✅ Merged **Merged:** 4/30/2026 **Merged by:** [@profvjreddi](https://github.com/profvjreddi) **Base:** `dev` ← **Head:** `fix/mlsysim-viz-test-missing-skip` --- ### 📝 Commits (2) - [`b464692`](https://github.com/harvard-edge/cs249r_book/commit/b4646922442a9f89052527e25cf19e05807e68f0) fix(mlsysim): skip viz test when matplotlib is not installed - [`7125cb0`](https://github.com/harvard-edge/cs249r_book/commit/7125cb047aab595a836e85c450f5de70f3e101fc) Merge branch 'dev' into fix/mlsysim-viz-test-missing-skip ### 📊 Changes **1 file changed** (+2 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `mlsysim/tests/test_evaluation_contract.py` (+2 -0) </details> ### 📄 Description ## Summary `test_scorecard_plot_accepts_scenario_evaluation_quantities` called `plot_evaluation_scorecard` unconditionally, but `matplotlib` is an optional dependency under `mlsysim[viz]` -- not installed in the base dev environment. Running `pytest` without the viz extra caused a hard `ImportError` instead of a graceful skip: ``` mlsysim/viz/plots.py:34: ImportError: matplotlib is required for plot generation. FAILED tests/test_evaluation_contract.py::test_scorecard_plot_accepts_scenario_evaluation_quantities ``` **Fix:** Add `pytest.importorskip("matplotlib")` at the start of the test, which is the standard pytest pattern for optional-dependency tests -- the test is skipped when matplotlib is absent and runs normally when `mlsysim[viz]` is installed. ## Before / after ``` # Before (base dev env, no matplotlib): FAILED test_evaluation_contract.py::test_scorecard_plot_accepts_scenario_evaluation_quantities # After: 385 passed, 3 skipped in 1.92s ``` ## Test plan - [ ] `uv run python -m pytest tests/` with base deps -- confirm test is skipped, not failed - [ ] `uv run python -m pytest tests/ --extras viz` (or with matplotlib installed) -- confirm test runs and passes --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-03 01:29:13 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#9219