Commit 6e1edea
authored
test: force headless Matplotlib backend for local + CI test runs (#197)
Local `pytest` runs were popping up real windows and, for a few tests,
hanging outright. Two separate problems, one root cause:
1. CI sets MPLBACKEND=Agg via the workflow env, but nothing did that
for local runs. Several modules (geom2d, geom3d, spline, animate)
import matplotlib.pyplot at module load time, so whatever backend
is active when they're first imported sticks for the whole
session. Locally that's the platform's interactive backend, hence
the popups.
Fix: tests/conftest.py sets os.environ.setdefault("MPLBACKEND",
"Agg") before anything else runs. conftest.py is guaranteed to
load before pytest imports any test module, so this closes the gap
for local runs without touching the CI workflow (now redundant
there, not conflicting). setdefault(), not a hard override, keeps
an escape hatch: `MPLBACKEND=MacOSX pytest ...` still shows you a
real plot when you actually want one.
2. Forcing Agg everywhere surfaced a latent bug: Twist/pose animation
tests use tranimate(..., wait=True), which busy-loops on
`plt.pause()` waiting for FuncAnimation's timer callback to
deregister itself. That deregistration is driven by the GUI event
loop, which Agg doesn't have — so under Agg the loop never exits.
Confirmed with a hard-alarm timeout: the affected test consumed a
full 12s budget with zero output, versus completing normally under
a real backend.
These tests were already skipped in CI (via an `os.environ.get(
"CI") == "true"` check) for a related but distinct reason — no
display in the CI runner. That check happened to also mask this
hang, but only in CI; locally, before this change, it ran fine
because a real backend really does pump the event loop. Once Agg
is forced locally too, the same hang would trigger there.
Fix: broadened the three affected skip conditions (test_animate in
test_transforms3d_plot.py; the two animate=True visualize tests
and the inline guard in test_spline.py) to additionally skip
whenever plt.get_backend() == "agg", which is the actual root
cause rather than the CI-env-var proxy for it. Purely additive —
no existing skip condition was removed, so CI behaviour is
unchanged. Everything else (plain, non-animated plotting tests)
now safely runs headless both locally and in CI, which is strictly
more coverage than before.
Verified: full suite passes locally with CI unset (339 passed, 3
skipped, 1.6s, no windows, no hangs) and with CI=true set (338 passed,
4 skipped, matching prior CI behaviour).1 parent c3eaff6 commit 6e1edea
3 files changed
Lines changed: 32 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
| 78 | + | |
78 | 79 | | |
79 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
72 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
| |||
110 | 118 | | |
111 | 119 | | |
112 | 120 | | |
113 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
114 | 124 | | |
115 | 125 | | |
116 | 126 | | |
| |||
0 commit comments