Skip to content

Commit fb2f641

Browse files
committed
Make test_examples_run actually draw a frame
<details><summary>Claude's draft</summary> test_examples_run() ran an example's main block and stopped there. Under the offscreen canvas that only builds the canvas and registers a draw function — nothing is drawn — so the draw function, which is the bulk of most examples, was never executed. That is how #829 slipped through CI: the imgui examples passed while ImguiWgpuBackend.render() was never entered. Draw one frame after running the main block, for every example that exposes a canvas. Also assert nothing was logged to the "rendercanvas" logger, because rendercanvas calls the draw function inside its log_exception() context: an exception there is logged and swallowed, and a frame still comes out, so drawing without checking the log would prove nothing. This drops the separate tests/test_util_imgui.py and the ci.yml change that went with it; the existing `pytest -v examples` job already installs imgui_bundle and now covers the backend. Verified with imgui_bundle 1.92.900: both imgui examples fail without the backend fix and pass with it, and the whole examples suite passes on 1.92.0 and 1.92.900. Resume this Claude session: ``` cd /home/mark/git/wgpu-py claude --resume 590dd7bc-312c-419e-ad3d-2c69d00943cd ``` </details>
1 parent 797a0d9 commit fb2f641

3 files changed

Lines changed: 18 additions & 45 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ jobs:
124124
EXPECT_LAVAPIPE: true
125125
run: |
126126
pytest -v examples
127-
# Separate invocation: examples/tests and tests both have a
128-
# testutils.py, so collecting them together shadows one of them.
129-
pytest -v tests/test_util_imgui.py
130127
131128
test-pyinstaller-build:
132129
name: Test PyInstaller

examples/tests/test_examples.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os
66
import importlib
7+
import logging
78
import runpy
89
import sys
910
from unittest.mock import patch
@@ -177,11 +178,24 @@ def update_diffs(module, is_similar, img, stored_img, *, atol):
177178

178179

179180
@pytest.mark.parametrize("module", examples_to_run)
180-
def test_examples_run(module, force_offscreen):
181+
def test_examples_run(module, force_offscreen, caplog):
181182
"""Run every example marked to see if they can run without error."""
182-
# use runpy so the module is not actually imported (and can be gc'd)
183-
# but also to be able to run the code in the __main__ block
184-
runpy.run_module(f"examples.{module}", run_name="__main__")
183+
with caplog.at_level(logging.ERROR, logger="rendercanvas"):
184+
# use runpy so the module is not actually imported (and can be gc'd)
185+
# but also to be able to run the code in the __main__ block
186+
module_globals = runpy.run_module(f"examples.{module}", run_name="__main__")
187+
188+
# The main block only sets up the canvas and hands it a draw function;
189+
# the offscreen canvas does not draw until asked. So ask, otherwise the
190+
# draw function (the bulk of most examples) is never executed.
191+
canvas = module_globals.get("canvas")
192+
if canvas is not None:
193+
canvas.draw()
194+
195+
# rendercanvas calls the draw function inside a log_exception() context, so
196+
# errors in it do not propagate; they only show up in the log.
197+
errors = [r for r in caplog.records if r.name == "rendercanvas"]
198+
assert not errors, caplog.text
185199

186200

187201
if __name__ == "__main__":

tests/test_util_imgui.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)