|
50 | 50 | SETBINARY = '' |
51 | 51 |
|
52 | 52 | NONEXISTING_CMD = ('nonexisting_i_hope',) |
| 53 | +# Ignore errors that indicate the command was not found |
| 54 | +NONEXISTING_ERRORS = (FileNotFoundError, NotADirectoryError, PermissionError) |
53 | 55 |
|
54 | 56 |
|
55 | 57 | class BaseTestCase(unittest.TestCase): |
@@ -310,9 +312,9 @@ def test_executable_takes_precedence(self): |
310 | 312 | # Verify first that the call succeeds without the executable arg. |
311 | 313 | pre_args = [sys.executable, "-c"] |
312 | 314 | self._assert_python(pre_args) |
313 | | - self.assertRaises((FileNotFoundError, PermissionError), |
| 315 | + self.assertRaises(NONEXISTING_ERRORS, |
314 | 316 | self._assert_python, pre_args, |
315 | | - executable="doesnotexist") |
| 317 | + executable=NONEXISTING_CMD[0]) |
316 | 318 |
|
317 | 319 | @unittest.skipIf(mswindows, "executable argument replaces shell") |
318 | 320 | def test_executable_replaces_shell(self): |
@@ -1150,13 +1152,10 @@ def test_leaking_fds_on_error(self): |
1150 | 1152 | # value for that limit, but Windows has 2048, so we loop |
1151 | 1153 | # 1024 times (each call leaked two fds). |
1152 | 1154 | for i in range(1024): |
1153 | | - with self.assertRaises(OSError) as c: |
| 1155 | + with self.assertRaises(NONEXISTING_ERRORS): |
1154 | 1156 | subprocess.Popen(NONEXISTING_CMD, |
1155 | 1157 | stdout=subprocess.PIPE, |
1156 | 1158 | stderr=subprocess.PIPE) |
1157 | | - # ignore errors that indicate the command was not found |
1158 | | - if c.exception.errno not in (errno.ENOENT, errno.EACCES): |
1159 | | - raise c.exception |
1160 | 1159 |
|
1161 | 1160 | def test_nonexisting_with_pipes(self): |
1162 | 1161 | # bpo-30121: Popen with pipes must close properly pipes on error. |
@@ -2539,7 +2538,7 @@ def test_leak_fast_process_del_killed(self): |
2539 | 2538 | # let some time for the process to exit, and create a new Popen: this |
2540 | 2539 | # should trigger the wait() of p |
2541 | 2540 | time.sleep(0.2) |
2542 | | - with self.assertRaises(OSError) as c: |
| 2541 | + with self.assertRaises(OSError): |
2543 | 2542 | with subprocess.Popen(NONEXISTING_CMD, |
2544 | 2543 | stdout=subprocess.PIPE, |
2545 | 2544 | stderr=subprocess.PIPE) as proc: |
@@ -2978,7 +2977,7 @@ def test_communicate_stdin(self): |
2978 | 2977 | self.assertEqual(proc.returncode, 1) |
2979 | 2978 |
|
2980 | 2979 | def test_invalid_args(self): |
2981 | | - with self.assertRaises((FileNotFoundError, PermissionError)) as c: |
| 2980 | + with self.assertRaises(NONEXISTING_ERRORS): |
2982 | 2981 | with subprocess.Popen(NONEXISTING_CMD, |
2983 | 2982 | stdout=subprocess.PIPE, |
2984 | 2983 | stderr=subprocess.PIPE) as proc: |
|
0 commit comments