summaryrefslogtreecommitdiffstats
path: root/Lib/test/support/__init__.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-18 16:56:43 (GMT)
committerGitHub <noreply@github.com>2020-06-18 16:56:43 (GMT)
commite8056180a13b6755e4e3e5505b7bf03f79da29fb (patch)
tree3b7ee3611f140572e4baefb9aab46a5b0fa4653e /Lib/test/support/__init__.py
parent3d974b2fc681ddd0ec722cf631008d5941da52b8 (diff)
downloadcpython-e8056180a13b6755e4e3e5505b7bf03f79da29fb.zip
cpython-e8056180a13b6755e4e3e5505b7bf03f79da29fb.tar.gz
cpython-e8056180a13b6755e4e3e5505b7bf03f79da29fb.tar.bz2
bpo-38377: Add support.skip_if_broken_multiprocessing_synchronize() (GH-20944) (GH-20962) (GH-20966)
On Linux, skip tests using multiprocessing if the current user cannot create a file in /dev/shm/ directory. Add the skip_if_broken_multiprocessing_synchronize() function to the test.support module. (cherry picked from commit ddbeb2f3e02a510c5784ffd74c5e09e8c70b5881) (cherry picked from commit b1e736113484c99acb57e4acb417b91a9e58e7ff)
Diffstat (limited to 'Lib/test/support/__init__.py')
-rw-r--r--Lib/test/support/__init__.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 0906e7a..b75dbd2 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -3377,3 +3377,26 @@ def save_restore_warnings_filters():
yield
finally:
warnings.filters[:] = old_filters
+
+
+def skip_if_broken_multiprocessing_synchronize():
+ """
+ Skip tests if the multiprocessing.synchronize module is missing, if there
+ is no available semaphore implementation, or if creating a lock raises an
+ OSError.
+ """
+
+ # Skip tests if the _multiprocessing extension is missing.
+ import_module('_multiprocessing')
+
+ # Skip tests if there is no available semaphore implementation:
+ # multiprocessing.synchronize requires _multiprocessing.SemLock.
+ synchronize = import_module('multiprocessing.synchronize')
+
+ try:
+ # bpo-38377: On Linux, creating a semaphore is the current user
+ # does not have the permission to create a file in /dev/shm.
+ # Create a semaphore to check permissions.
+ synchronize.Lock(ctx=None)
+ except OSError as exc:
+ raise unittest.SkipTest(f"broken multiprocessing SemLock: {exc!r}")