bpo-28009: Fix uuid SkipUnless logic to be based on platform programs capable of introspection (GH-12777)
uuid could try fallback methods that had no chance of working on a particular
platform, and this could cause spurious test failures, as well as degraded
performance as fallback options were tried and failed.
This fixes both the uuid module and its test's SkipUnless logic to use a
prefiltered list of techniques that may at least potentially work on that platform.
Patch by Michael Felt (aixtools).
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index 992ef0c..92642d2 100644
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -462,8 +462,7 @@
with unittest.mock.patch.multiple(
self.uuid,
_node=None, # Ignore any cached node value.
- _NODE_GETTERS_WIN32=[too_large_getter],
- _NODE_GETTERS_UNIX=[too_large_getter],
+ _GETTERS=[too_large_getter],
):
node = self.uuid.getnode()
self.assertTrue(0 < node < (1 << 48), '%012x' % node)
@@ -673,7 +672,7 @@
class BaseTestInternals:
- uuid = None
+ _uuid = py_uuid
@unittest.skipUnless(os.name == 'posix', 'requires Posix')
def test_find_mac(self):
@@ -708,27 +707,32 @@
self.assertTrue(0 < node < (1 << 48),
"%s is not an RFC 4122 node ID" % hex)
- @unittest.skipUnless(os.name == 'posix', 'requires Posix')
+ @unittest.skipUnless(_uuid._ifconfig_getnode in _uuid._GETTERS,
+ "ifconfig is not used for introspection on this platform")
def test_ifconfig_getnode(self):
node = self.uuid._ifconfig_getnode()
self.check_node(node, 'ifconfig')
- @unittest.skipUnless(os.name == 'posix', 'requires Posix')
+ @unittest.skipUnless(_uuid._ip_getnode in _uuid._GETTERS,
+ "ip is not used for introspection on this platform")
def test_ip_getnode(self):
node = self.uuid._ip_getnode()
self.check_node(node, 'ip')
- @unittest.skipUnless(os.name == 'posix', 'requires Posix')
+ @unittest.skipUnless(_uuid._arp_getnode in _uuid._GETTERS,
+ "arp is not used for introspection on this platform")
def test_arp_getnode(self):
node = self.uuid._arp_getnode()
self.check_node(node, 'arp')
- @unittest.skipUnless(os.name == 'posix', 'requires Posix')
+ @unittest.skipUnless(_uuid._lanscan_getnode in _uuid._GETTERS,
+ "lanscan is not used for introspection on this platform")
def test_lanscan_getnode(self):
node = self.uuid._lanscan_getnode()
self.check_node(node, 'lanscan')
- @unittest.skipUnless(os.name == 'posix', 'requires Posix')
+ @unittest.skipUnless(_uuid._netstat_getnode in _uuid._GETTERS,
+ "netstat is not used for introspection on this platform")
def test_netstat_getnode(self):
node = self.uuid._netstat_getnode()
self.check_node(node, 'netstat')