Repository navigation
force tests to use matplotlib Agg backend - #240
Merged
Merged
Conversation
stefansc1
approved these changes
Oct 12, 2026
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.
Tests crash with
_tkinter.TclError: Can't find a usable tk.tclProblem
Running
pytest testscan fail with:The traceback points into
tkinter'sTk.__init__(_tkinter.create(...)), triggered fromsimba/report.py::generate_plots():plt.ion()switches matplotlib into interactive mode regardless ofargs.show_plots(that flagonly guards the later explicit
plt.show()call). When matplotlib has no backend configuredexplicitly and runs on a machine where Tk is available, it auto-selects an interactive GUI
backend (
TkAggon Windows). Creating the figure then instantiates real Tk/ttk widgets(e.g. for the toolbar), which is what pulls in
ttk::LoadThemesand tries to source the ttktheme files. The underlying Tcl/Tk installation can be completely intact (confirmed via
python -c "import tkinter; tkinter.Tk()"and by checking the referenced file on disk) — thereal issue is that the test suite ends up creating a real GUI window at all.
This is fragile (depends on the local machine's Tk/ttk setup, antivirus/EDR file scanning, etc.)
and unnecessary: automated tests should not open interactive windows or depend on a display being
available.
Solution
Force matplotlib onto the non-interactive
Aggbackend for the whole test session, intests/conftest.py:conftest.pyis always loaded by pytest before any test module, so this is the one place thatreliably runs before
matplotlib.pyplotgets imported anywhere (directly or viasimba.report). Matplotlib's backend can only be set before the firstpyplotimport, sosetting it per test file would be unreliable once any earlier test has already imported
simba.report.Aggstill produces the.png/.pdffiles viaplt.savefig(...), so plot-generation testskeep working; only the interactive window is skipped.
generate_plotswithargs.show_plots = Trueoutside ofpytest) is unaffected, since
conftest.pyonly applies to the test session.Implementation (branch
fix/plot_tests)tests/conftest.py: addedmatplotlib.use("Agg")before other imports.