Skip to content

Commit

Permalink
[test] Add skipExecIf which just skips the running of the test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 committed Mar 9, 2024
1 parent 2ba2078 commit 2ba59e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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')
Expand Down
21 changes: 18 additions & 3 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2ba59e7

Please sign in to comment.