diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 4c620ccae9c84c..c4abd9d8a5280a 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1418,9 +1418,20 @@ def test_urandom_failure(self): import errno import os import resource - soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE) - resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_limit)) + try: + resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_limit)) + except (ValueError,OSError): + for i in range(1, hard_limit + 1): + try: + os.open(os.devnull, os.O_RDONLY) + except OSError as e: + if e.errno == errno.EMFILE: + break + else: + continue + else: + pass try: os.urandom(16) except OSError as e: @@ -1516,7 +1527,8 @@ def mock_execve(name, *args): os.execve = orig_execve os.defpath = orig_defpath - +@unittest.skipUnless(hasattr(os, 'execv'), + "No os.execv or os.execve function to test.") class ExecTests(unittest.TestCase): @unittest.skipIf(USING_LINUXTHREADS, "avoid triggering a linuxthreads bug: see issue #4970") diff --git a/Misc/NEWS.d/next/Tests/2019-03-14-14-50-11.bpo-31904.iu3g9k.rst b/Misc/NEWS.d/next/Tests/2019-03-14-14-50-11.bpo-31904.iu3g9k.rst new file mode 100644 index 00000000000000..10dda8ca15a926 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-03-14-14-50-11.bpo-31904.iu3g9k.rst @@ -0,0 +1,2 @@ +Improve the test_urandom_failure. +Skip the ExecTests test cases in test_os.py for VxWorks.