]> granicus.if.org Git - python/commitdiff
Fix test_os.GetRandomTests()
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 7 Sep 2016 02:57:40 +0000 (19:57 -0700)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 7 Sep 2016 02:57:40 +0000 (19:57 -0700)
Issue #27778: Skip getrandom() tests if getrandom() fails with ENOSYS.

Lib/test/test_os.py

index 52056725ce5bcc216b7409c769e5bb49f859ae7e..2de94c643d425ca25e1a305b46b4cae9219b6f12 100644 (file)
@@ -1271,6 +1271,18 @@ class URandomTests(unittest.TestCase):
 
 @unittest.skipUnless(hasattr(os, 'getrandom'), 'need os.getrandom()')
 class GetRandomTests(unittest.TestCase):
+    @classmethod
+    def setUpClass(cls):
+        try:
+            os.getrandom(1)
+        except OSError as exc:
+            if exc.errno == errno.ENOSYS:
+                # Python compiled on a more recent Linux version
+                # than the current Linux kernel
+                raise unittest.SkipTest("getrandom() syscall fails with ENOSYS")
+            else:
+                raise
+
     def test_getrandom_type(self):
         data = os.getrandom(16)
         self.assertIsInstance(data, bytes)