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>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 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:
dev← Head:fix/mlsysim-viz-test-missing-skip📝 Commits (2)
b464692fix(mlsysim): skip viz test when matplotlib is not installed7125cb0Merge 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_quantitiescalledplot_evaluation_scorecardunconditionally, butmatplotlibis an optional dependency undermlsysim[viz]-- not installed in the base dev environment. Runningpytestwithout the viz extra caused a hardImportErrorinstead of a graceful skip: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 whenmlsysim[viz]is installed.Before / after
Test plan
uv run python -m pytest tests/with base deps -- confirm test is skipped, not faileduv 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.