Skip to content

Commit f825b44

Browse files
committed
[test] Add skipExecIf which just skips the running of the test
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 25125ce commit f825b44

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

test/common.py

Lines changed: 3 additions & 0 deletions
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

Lines changed: 18 additions & 3 deletions
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)