Repository navigation
fix: pin the Agg matplotlib backend for the test suite (#280) - #287
Merged
Merged
Conversation
Nothing in the repository set a backend, so the plot tests used whatever the host resolved to. On a host with an interactive default (tkagg on Windows) one plot test per full run failed on the display connection — a different one each time — while each passed alone. conftest.py now pins Agg with matplotlib.use(force=True) for the process and exports MPLBACKEND for spawned subprocesses, so a full run no longer depends on whether the host can open a display. A small regression test asserts the suite runs headless.
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.
Summary
Fixes #280. The repository pinned no matplotlib backend anywhere (
matplotlib.use/MPLBACKENDappear nowhere in the tree), so the plot tests opened whatever display connection the host's default backend wanted. On the reporter's Windows host that resolved totkagg, and one plot test per full run failed with_tkinter.TclError— a different one each time, each passing alone. Their own third run showedMPLBACKEND=Aggmakes the suite deterministic.tests/conftest.pynow pins the headless backend at collection time:matplotlib.use("Agg", force=True)for the test process itself (force so it holds even if a plugin imported matplotlib first),os.environ.setdefault("MPLBACKEND", "Agg")so subprocesses the tests spawn inherit it,ImportErrorso a core-only environment without the[ml]extra still collects.No product code changes — the backend choice for real CLI runs is untouched; this pins only the test suite.
Testing
tests/unit/test_matplotlib_backend.pyasserts the suite runs on Agg and exportsMPLBACKEND.test_audio_quality_plots.py,test_demographic_analyzer.py,test_report_generator.py+ the new file — 53 passed.MPLBACKEND=tkaggon this headless host, the suite still resolves to Agg and all plot tests pass. (The pre-fix failure itself is host-specific — this Linux box's Tk happens to be usable — but the issue's three-run table already established the mechanism.)ruff checkandruff format --checkclean.