Skip to content

Commit 49e8f2d

Browse files
author
Xavier de Gaye
committed
Issue 28668: Skip tests where instanciation of multiprocessing.Queue
would raise ImportError
1 parent 5ae6c77 commit 49e8f2d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Lib/test/support/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
9090
"requires_IEEE_754", "skip_unless_xattr", "requires_zlib",
9191
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
92+
"requires_multiprocessing_queue",
9293
# sys
9394
"is_jython", "check_impl_detail",
9495
# network
@@ -1731,6 +1732,22 @@ def impl_detail(msg=None, **guards):
17311732
msg = msg.format(' or '.join(guardnames))
17321733
return unittest.skip(msg)
17331734

1735+
_have_mp_queue = None
1736+
def requires_multiprocessing_queue(test):
1737+
"""Skip decorator for tests that use multiprocessing.Queue."""
1738+
global _have_mp_queue
1739+
if _have_mp_queue is None:
1740+
import multiprocessing
1741+
# Without a functioning shared semaphore implementation attempts to
1742+
# instantiate a Queue will result in an ImportError (issue #3770).
1743+
try:
1744+
multiprocessing.Queue()
1745+
_have_mp_queue = True
1746+
except ImportError:
1747+
_have_mp_queue = False
1748+
msg = "requires a functioning shared semaphore implementation"
1749+
return test if _have_mp_queue else unittest.skip(msg)(test)
1750+
17341751
def _parse_guards(guards):
17351752
# Returns a tuple ({platform_name: run_me}, default_value)
17361753
if not guards:

Lib/test/test_logging.py

+2
Original file line numberDiff line numberDiff line change
@@ -3066,6 +3066,7 @@ def test_handle_called_with_queue_queue(self, mock_handle):
30663066
self.assertEqual(mock_handle.call_count, 5 * self.repeat,
30673067
'correct number of handled log messages')
30683068

3069+
@support.requires_multiprocessing_queue
30693070
@patch.object(logging.handlers.QueueListener, 'handle')
30703071
def test_handle_called_with_mp_queue(self, mock_handle):
30713072
for i in range(self.repeat):
@@ -3082,6 +3083,7 @@ def get_all_from_queue(log_queue):
30823083
except queue.Empty:
30833084
return []
30843085

3086+
@support.requires_multiprocessing_queue
30853087
def test_no_messages_in_queue_after_stop(self):
30863088
"""
30873089
Five messages are logged then the QueueListener is stopped. This

0 commit comments

Comments
 (0)