Skip to content

Commit a589a22

Browse files
authored
[test] Add skipExecIf which just skips the running of the test (#21499)
This means that even in CI when we might skip certain tests for graphics or sounds we still get some assurance that the test code compiles.
1 parent 64feaf1 commit a589a22

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

test/common.py

+3
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ def setUp(self):
863863
super().setUp()
864864
self.js_engines = config.JS_ENGINES.copy()
865865
self.settings_mods = {}
866+
self.skip_exec = None
866867
self.emcc_args = ['-Wclosure', '-Werror', '-Wno-limited-postlink-optimizations']
867868
# TODO(https://github.com/emscripten-core/emscripten/issues/11121)
868869
# For historical reasons emcc compiles and links as C++ by default.
@@ -1967,6 +1968,8 @@ def assert_out_queue_empty(self, who):
19671968
def run_browser(self, html_file, expected=None, message=None, timeout=None, extra_tries=1):
19681969
if not has_browser():
19691970
return
1971+
if self.skip_exec:
1972+
self.skipTest('skipping test execution: ' + self.skip_exec)
19701973
if BrowserCore.unresponsive_tests >= BrowserCore.MAX_UNRESPONSIVE_TESTS:
19711974
self.skipTest('too many unresponsive tests, skipping remaining tests')
19721975
self.assert_out_queue_empty('previous test')

test/test_browser.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,24 @@ def decorated(self, *args, **kwargs):
187187
return decorated
188188

189189

190-
requires_graphics_hardware = unittest.skipIf(os.getenv('EMTEST_LACKS_GRAPHICS_HARDWARE'), "This test requires graphics hardware")
191-
requires_sound_hardware = unittest.skipIf(os.getenv('EMTEST_LACKS_SOUND_HARDWARE'), "This test requires sound hardware")
192-
requires_offscreen_canvas = unittest.skipIf(os.getenv('EMTEST_LACKS_OFFSCREEN_CANVAS'), "This test requires a browser with OffscreenCanvas")
190+
def skipExecIf(cond, message):
191+
def decorator(f):
192+
assert callable(f)
193+
194+
@wraps(f)
195+
def decorated(self, *args, **kwargs):
196+
if cond:
197+
self.skip_exec = message
198+
f(self, *args, **kwargs)
199+
200+
return decorated
201+
202+
return decorator
203+
204+
205+
requires_graphics_hardware = skipExecIf(os.getenv('EMTEST_LACKS_GRAPHICS_HARDWARE'), 'This test requires graphics hardware')
206+
requires_sound_hardware = skipExecIf(os.getenv('EMTEST_LACKS_SOUND_HARDWARE'), 'This test requires sound hardware')
207+
requires_offscreen_canvas = skipExecIf(os.getenv('EMTEST_LACKS_OFFSCREEN_CANVAS'), 'This test requires a browser with OffscreenCanvas')
193208

194209

195210
class browser(BrowserCore):

0 commit comments

Comments
 (0)