From 2ba59e7e0b11819745f8fa3cbdb0c49b987c1eca 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..19d0245dbee4a 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.skipExec = 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.skipExec: + self.skipTest('skipping test execution: ' + self.skipExec) 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 0c7048c7c2eb9..8520f08aa09b6 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.skipExec = 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):