From f825b44d2bb895f28237a8fb352eca4c29b4750a Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sat, 9 Mar 2024 09:14:22 -0800 Subject: [PATCH] [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. --- test/common.py | 3 +++ test/test_browser.py | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/test/common.py b/test/common.py index 78bbd5d591ab9..43aa9f56bc86d 100644 --- a/test/common.py +++ b/test/common.py @@ -863,6 +863,7 @@ def setUp(self): super().setUp() self.js_engines = config.JS_ENGINES.copy() self.settings_mods = {} + self.skip_exec = None self.emcc_args = ['-Wclosure', '-Werror', '-Wno-limited-postlink-optimizations'] # TODO(https://github.com/emscripten-core/emscripten/issues/11121) # For historical reasons emcc compiles and links as C++ by default. @@ -1967,6 +1968,8 @@ def assert_out_queue_empty(self, who): def run_browser(self, html_file, expected=None, message=None, timeout=None, extra_tries=1): if not has_browser(): return + if self.skip_exec: + self.skipTest('skipping test execution: ' + self.skip_exec) if BrowserCore.unresponsive_tests >= BrowserCore.MAX_UNRESPONSIVE_TESTS: self.skipTest('too many unresponsive tests, skipping remaining tests') self.assert_out_queue_empty('previous test') diff --git a/test/test_browser.py b/test/test_browser.py index c58099a5df6c0..0bffedfd6d50a 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -187,9 +187,24 @@ def decorated(self, *args, **kwargs): return decorated -requires_graphics_hardware = unittest.skipIf(os.getenv('EMTEST_LACKS_GRAPHICS_HARDWARE'), "This test requires graphics hardware") -requires_sound_hardware = unittest.skipIf(os.getenv('EMTEST_LACKS_SOUND_HARDWARE'), "This test requires sound hardware") -requires_offscreen_canvas = unittest.skipIf(os.getenv('EMTEST_LACKS_OFFSCREEN_CANVAS'), "This test requires a browser with OffscreenCanvas") +def skipExecIf(cond, message): + def decorator(f): + assert callable(f) + + @wraps(f) + def decorated(self, *args, **kwargs): + if cond: + self.skip_exec = message + f(self, *args, **kwargs) + + return decorated + + return decorator + + +requires_graphics_hardware = skipExecIf(os.getenv('EMTEST_LACKS_GRAPHICS_HARDWARE'), 'This test requires graphics hardware') +requires_sound_hardware = skipExecIf(os.getenv('EMTEST_LACKS_SOUND_HARDWARE'), 'This test requires sound hardware') +requires_offscreen_canvas = skipExecIf(os.getenv('EMTEST_LACKS_OFFSCREEN_CANVAS'), 'This test requires a browser with OffscreenCanvas') class browser(BrowserCore):