Skip to content

fix(tests): examples run from the suite draw with matplotlib's Agg - #120

Merged
mahdi-shafiei merged 1 commit into
mainfrom
fix/examples-draw-off-screen
Nov 18, 2026
Merged

mahdi-shafiei merged 1 commit into
mainfrom
fix/examples-draw-off-screen

Conversation

@mahdi-shafiei

Copy link
Copy Markdown
Contributor

Summary

 [tool.pytest_env]
 JAX_SKIP_CUDA_CONSTRAINTS_CHECK = {skip_if_set = true, value = "1"}
+MPLBACKEND = {skip_if_set = true, value = "Agg"}

An example started from the suite (run_python, which hands the test process's environment to the child) draws with Agg on every machine, as in substrax, calibrax, receptifex and seismifex. substrax's notebook runner sets its own inline backend for a kernel, so generated pages are unchanged.

Evidence

  • Before, with DISPLAY=:1 and no MPLBACKEND: 06_mnist_tutorial and the MixUp/CutMix tutorial abort with Tcl_AsyncDelete: async handler deleted by the wrong thread in some runs (both failed in one run, both passed in the next); with no display both pass. The two new tests fail: the child sees no MPLBACKEND, and [tool.pytest_env] has none.
  • After, with DISPLAY=:1: the two examples and both new tests pass in three runs of three, with no Tcl error. Under Agg matplotlib creates no Tk object. The fast example, tooling-contract and hygiene tests pass, 169 of 169, and the pre-commit hooks pass on the changed files.

Merge Danger

Door: two-way

Blast Radius: test environment

  • Only test runs change: pytest-env applies to the test process and what it starts. A developer who sets MPLBACKEND keeps theirs (skip_if_set).
  • No test under tests/ imports matplotlib apart from the examples' runs and a dependency utility.

The test run set no MPLBACKEND, so on a machine with a display
matplotlib picked TkAgg for an example started through run_python, and
06_mnist_tutorial and the MixUp/CutMix tutorial aborted on
"Tcl_AsyncDelete: async handler deleted by the wrong thread" in some
runs. CI has no display and never met it.

[tool.pytest_env] sets MPLBACKEND to Agg unless the caller set one, the
line substrax, calibrax, receptifex and seismifex carry, and run_python
hands the test process's environment to each child. substrax's notebook
runner sets its own inline backend for a kernel, so pages are unchanged.

Two tests pin it: an example's process sees the test run's MPLBACKEND
with DISPLAY set, and the pytest-env default is Agg. Both failed before
the change. With DISPLAY=:1, the two examples and both tests passed in
three runs of three.
@mahdi-shafiei
mahdi-shafiei marked this pull request as ready for review November 18, 2026 18:25
@mahdi-shafiei
mahdi-shafiei merged commit 3901626 into main Nov 18, 2026
19 of 20 checks passed
@mahdi-shafiei
mahdi-shafiei deleted the fix/examples-draw-off-screen branch November 18, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant