From a931c2a548955031eaf2c9d7cf7b58e45dad8804 Mon Sep 17 00:00:00 2001 From: ysun1 Date: Thu, 14 Mar 2019 14:44:41 +0800 Subject: [PATCH 1/2] improve the test_urandom_failure and skip the ExecTests test cases in test_os.py --- Lib/test/test_os.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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") From c274a4056ab8f88d73d86f842b8ff89006d8357a Mon Sep 17 00:00:00 2001 From: ysun1 Date: Thu, 14 Mar 2019 14:53:39 +0800 Subject: [PATCH 2/2] Add news file --- Misc/NEWS.d/next/Tests/2019-03-14-14-50-11.bpo-31904.iu3g9k.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-03-14-14-50-11.bpo-31904.iu3g9k.rst 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.