summaryrefslogtreecommitdiffstats
path: root/Lib/test/support/threading_helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/support/threading_helper.py')
-rw-r--r--Lib/test/support/threading_helper.py15
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)