diff options
author | Christian Heimes <christian@python.org> | 2022-04-07 07:22:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-07 07:22:47 (GMT) |
commit | 2b16a08bc77475917dd5c96417aef4c5210b45ac (patch) | |
tree | 6188ad8008760a8710ba6692c44c25157c69d981 /Lib/test/support/threading_helper.py | |
parent | 5aee46b31ba37d65cdf4d5a96cabb8835c508deb (diff) | |
download | cpython-2b16a08bc77475917dd5c96417aef4c5210b45ac.zip cpython-2b16a08bc77475917dd5c96417aef4c5210b45ac.tar.gz cpython-2b16a08bc77475917dd5c96417aef4c5210b45ac.tar.bz2 |
bpo-40280: Detect missing threading on WASM platforms (GH-32352)
Co-authored-by: Brett Cannon <brett@python.org>
Diffstat (limited to 'Lib/test/support/threading_helper.py')
-rw-r--r-- | Lib/test/support/threading_helper.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/support/threading_helper.py b/Lib/test/support/threading_helper.py index 2ae4577..7b636f0 100644 --- a/Lib/test/support/threading_helper.py +++ b/Lib/test/support/threading_helper.py @@ -4,6 +4,7 @@ import functools import sys import threading import time +import unittest from test import support @@ -210,7 +211,7 @@ class catch_threading_exception: def _can_start_thread() -> bool: - """Detect if Python can start new threads. + """Detect whether Python can start new threads. Some WebAssembly platforms do not provide a working pthread implementation. Thread support is stubbed and any attempt @@ -234,3 +235,15 @@ def _can_start_thread() -> bool: return True can_start_thread = _can_start_thread() + +def requires_working_threading(*, module=False): + """Skip tests or modules that require working threading. + + Can be used as a function/class decorator or to skip an entire module. + """ + msg = "requires threading support" + if module: + if not can_start_thread: + raise unittest.SkipTest(msg) + else: + return unittest.skipUnless(can_start_thread, msg) |