diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-01-25 21:39:36 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2018-01-25 21:39:36 (GMT) |
commit | 255dbd2102d5dec5ffbd0b94084377e98c3b56c4 (patch) | |
tree | 14d0e637e23a0a0c9a09f4e495a585151b9ad408 /Lib/test/test_subprocess.py | |
parent | 196b8cbab2b5044b92077f0b3c07c798fff68bc6 (diff) | |
download | cpython-255dbd2102d5dec5ffbd0b94084377e98c3b56c4.zip cpython-255dbd2102d5dec5ffbd0b94084377e98c3b56c4.tar.gz cpython-255dbd2102d5dec5ffbd0b94084377e98c3b56c4.tar.bz2 |
bpo-32667: Fix tests when $PATH contains a file (GH-5322) (#5323)
Some tests failed when the PATH environment variable contained a path
to an existing file. Fix tests to ignore also NotADirectoryError, not
only FileNotFoundError and PermissionError.
(cherry picked from commit b31206a223955d614d7769f95fb979d60f77bf87)
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r-- | Lib/test/test_subprocess.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 5016513..d7eb982 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -50,6 +50,8 @@ else: SETBINARY = '' NONEXISTING_CMD = ('nonexisting_i_hope',) +# Ignore errors that indicate the command was not found +NONEXISTING_ERRORS = (FileNotFoundError, NotADirectoryError, PermissionError) class BaseTestCase(unittest.TestCase): @@ -310,9 +312,9 @@ class ProcessTestCase(BaseTestCase): # Verify first that the call succeeds without the executable arg. pre_args = [sys.executable, "-c"] self._assert_python(pre_args) - self.assertRaises((FileNotFoundError, PermissionError), + self.assertRaises(NONEXISTING_ERRORS, self._assert_python, pre_args, - executable="doesnotexist") + executable=NONEXISTING_CMD[0]) @unittest.skipIf(mswindows, "executable argument replaces shell") def test_executable_replaces_shell(self): @@ -1150,13 +1152,10 @@ class ProcessTestCase(BaseTestCase): # value for that limit, but Windows has 2048, so we loop # 1024 times (each call leaked two fds). for i in range(1024): - with self.assertRaises(OSError) as c: + with self.assertRaises(NONEXISTING_ERRORS): subprocess.Popen(NONEXISTING_CMD, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # ignore errors that indicate the command was not found - if c.exception.errno not in (errno.ENOENT, errno.EACCES): - raise c.exception def test_nonexisting_with_pipes(self): # bpo-30121: Popen with pipes must close properly pipes on error. @@ -2539,7 +2538,7 @@ class POSIXProcessTestCase(BaseTestCase): # let some time for the process to exit, and create a new Popen: this # should trigger the wait() of p time.sleep(0.2) - with self.assertRaises(OSError) as c: + with self.assertRaises(OSError): with subprocess.Popen(NONEXISTING_CMD, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: @@ -2978,7 +2977,7 @@ class ContextManagerTests(BaseTestCase): self.assertEqual(proc.returncode, 1) def test_invalid_args(self): - with self.assertRaises((FileNotFoundError, PermissionError)) as c: + with self.assertRaises(NONEXISTING_ERRORS): with subprocess.Popen(NONEXISTING_CMD, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: |