From 71d2a61b4577b0c2b9759015c8b5fd5bc1ab4979 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Tue, 18 Aug 2026 21:49:10 -0400 Subject: [PATCH] Draw a frame in test_examples_run
Claude's draft test_examples_run() ran an example's __main__ block and stopped there. Under the offscreen canvas that only constructs the canvas and registers a draw function, so nothing is drawn and the draw function -- the bulk of most examples -- was never executed. Draw one frame for every example that exposes a canvas. Drawing is not enough on its own: rendercanvas calls the draw function inside its log_exception() context, so an exception there is logged to the "rendercanvas" logger and swallowed, and a frame still comes out. Assert that nothing was logged there. This makes the imgui examples fail against imgui_bundle 1.92.900, which is the bug reported in https://github.com/pygfx/wgpu-py/issues/829 and is fixed in the next commit. Resume this Claude session: ``` cd /home/mark/git/wgpu-py claude --resume 590dd7bc-312c-419e-ad3d-2c69d00943cd ```
--- examples/tests/test_examples.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/tests/test_examples.py b/examples/tests/test_examples.py index 2cffb502..4fdc0f79 100644 --- a/examples/tests/test_examples.py +++ b/examples/tests/test_examples.py @@ -4,6 +4,7 @@ import os import importlib +import logging import runpy import sys from unittest.mock import patch @@ -177,11 +178,24 @@ def update_diffs(module, is_similar, img, stored_img, *, atol): @pytest.mark.parametrize("module", examples_to_run) -def test_examples_run(module, force_offscreen): +def test_examples_run(module, force_offscreen, caplog): """Run every example marked to see if they can run without error.""" - # use runpy so the module is not actually imported (and can be gc'd) - # but also to be able to run the code in the __main__ block - runpy.run_module(f"examples.{module}", run_name="__main__") + with caplog.at_level(logging.ERROR, logger="rendercanvas"): + # use runpy so the module is not actually imported (and can be gc'd) + # but also to be able to run the code in the __main__ block + module_globals = runpy.run_module(f"examples.{module}", run_name="__main__") + + # The main block only sets up the canvas and hands it a draw function; + # the offscreen canvas does not draw until asked. So ask, otherwise the + # draw function (the bulk of most examples) is never executed. + canvas = module_globals.get("canvas") + if canvas is not None: + canvas.draw() + + # rendercanvas calls the draw function inside a log_exception() context, so + # errors in it do not propagate; they only show up in the log. + errors = [r for r in caplog.records if r.name == "rendercanvas"] + assert not errors, caplog.text if __name__ == "__main__":