From 9ce7b323248f86bc7ffd332fac0432caba860ebf Mon Sep 17 00:00:00 2001 From: Lars Bogner Date: Mon, 10 Aug 2026 11:56:36 +0200 Subject: [PATCH] Fix test_render_all_run_gallery_invokes_subprocess clobbering LaTeX's own subprocess.run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit render_mod.subprocess is the stdlib subprocess module itself, not a copy — patching .run unconditionally also intercepted the real subprocess.run calls matplotlib's texmanager makes to compile LaTeX during savefig, so those returned the test's fake return value instead of a real CompletedProcess and crashed with AttributeError: 'NoneType' object has no attribute 'stdout' on any environment where render_all runs before the gallery call (i.e. everywhere but this dev machine's warm state that happened to mask it). Only intercept the "gallery generate" call now; everything else passes through to the real subprocess.run. Co-Authored-By: Claude Sonnet 5 --- tests/test_render.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/test_render.py b/tests/test_render.py index f5691c1..f1ec9d5 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -98,10 +98,21 @@ def test_render_router_diagnostics_and_edge_cases(tmp_path: Path): def test_render_all_run_gallery_invokes_subprocess(tmp_path: Path, monkeypatch): + # render_mod.subprocess *is* the stdlib subprocess module, so a blanket + # patch of .run would also swallow the real subprocess.run calls + # matplotlib's texmanager makes to compile LaTeX during savefig — only + # intercept the "gallery generate" call itself and pass everything else + # (LaTeX included) through to the real subprocess.run. calls = [] - monkeypatch.setattr( - render_mod.subprocess, "run", lambda *a, **k: calls.append((a, k)) - ) + real_run = render_mod.subprocess.run + + def fake_run(*a, **k): + if a and a[0] and a[0][0] == "gallery": + calls.append((a, k)) + return None + return real_run(*a, **k) + + monkeypatch.setattr(render_mod.subprocess, "run", fake_run) reduced = [ Reduced( "s",