[MNT] Fix Tkinter UI crashes during test suite execution via headless Matplotlib backend#2142
Open
Siddhazntx wants to merge 5 commits intosktime:mainfrom
Open
[MNT] Fix Tkinter UI crashes during test suite execution via headless Matplotlib backend#2142Siddhazntx wants to merge 5 commits intosktime:mainfrom
Siddhazntx wants to merge 5 commits intosktime:mainfrom
Conversation
0eabe9b to
41807c2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2142 +/- ##
=======================================
Coverage ? 86.63%
=======================================
Files ? 165
Lines ? 9732
Branches ? 0
=======================================
Hits ? 8431
Misses ? 1301
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Reference Issues/PRs
Fixes #2140
What does this implement/fix? Explain your changes.
When running the test suite locally (specifically on Windows Conda environments or headless CI environments), tests that invoke model plotting (such as test_temporal_fusion_transformer.py::test_integration) cause the test suite to crash.
The crash occurs because self.plot_prediction() calls plt.subplots(). If the environment defaults to a GUI backend like TkAgg but lacks properly configured UI libraries, it attempts to open a physical window and fails.
Terminal Error Traceback
The Fix:
This PR updates tests/conftest.py to explicitly set matplotlib.use("Agg") at the very top of the file. This globally forces Matplotlib to use the headless Agg backend during pytest execution. Plots are now safely rendered in memory without attempting to launch physical GUI windows.
What should a reviewer concentrate their feedback on?
The placement of matplotlib.use("Agg") in conftest.py. It is placed at the top of the file to ensure it executes before any pytorch_forecasting modules are imported, which might otherwise prematurely initialize pyplot with the default backend.
PR checklist
pre-commit install.To run hooks independent of commit, execute
pre-commit run --all-files