mirror of https://github.com/python/cpython
Fix test_os.GetRandomTests()
Issue #27778: Skip getrandom() tests if getrandom() fails with ENOSYS.
This commit is contained in:
parent
6cebd48425
commit
173a1f3dc7
|
@ -1271,6 +1271,18 @@ class URandomTests(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, 'getrandom'), 'need os.getrandom()')
|
@unittest.skipUnless(hasattr(os, 'getrandom'), 'need os.getrandom()')
|
||||||
class GetRandomTests(unittest.TestCase):
|
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):
|
def test_getrandom_type(self):
|
||||||
data = os.getrandom(16)
|
data = os.getrandom(16)
|
||||||
self.assertIsInstance(data, bytes)
|
self.assertIsInstance(data, bytes)
|
||||||
|
|
Loading…
Reference in New Issue