|
46 | 46 | SETBINARY = ''
|
47 | 47 |
|
48 | 48 | NONEXISTING_CMD = ('nonexisting_i_hope',)
|
| 49 | +# Ignore errors that indicate the command was not found |
| 50 | +NONEXISTING_ERRORS = (FileNotFoundError, NotADirectoryError, PermissionError) |
49 | 51 |
|
50 | 52 |
|
51 | 53 | class BaseTestCase(unittest.TestCase):
|
@@ -306,9 +308,9 @@ def test_executable_takes_precedence(self):
|
306 | 308 | # Verify first that the call succeeds without the executable arg.
|
307 | 309 | pre_args = [sys.executable, "-c"]
|
308 | 310 | self._assert_python(pre_args)
|
309 |
| - self.assertRaises((FileNotFoundError, PermissionError), |
| 311 | + self.assertRaises(NONEXISTING_ERRORS, |
310 | 312 | self._assert_python, pre_args,
|
311 |
| - executable="doesnotexist") |
| 313 | + executable=NONEXISTING_CMD[0]) |
312 | 314 |
|
313 | 315 | @unittest.skipIf(mswindows, "executable argument replaces shell")
|
314 | 316 | def test_executable_replaces_shell(self):
|
@@ -1146,13 +1148,10 @@ def test_leaking_fds_on_error(self):
|
1146 | 1148 | # value for that limit, but Windows has 2048, so we loop
|
1147 | 1149 | # 1024 times (each call leaked two fds).
|
1148 | 1150 | for i in range(1024):
|
1149 |
| - with self.assertRaises(OSError) as c: |
| 1151 | + with self.assertRaises(NONEXISTING_ERRORS): |
1150 | 1152 | subprocess.Popen(NONEXISTING_CMD,
|
1151 | 1153 | stdout=subprocess.PIPE,
|
1152 | 1154 | stderr=subprocess.PIPE)
|
1153 |
| - # ignore errors that indicate the command was not found |
1154 |
| - if c.exception.errno not in (errno.ENOENT, errno.EACCES): |
1155 |
| - raise c.exception |
1156 | 1155 |
|
1157 | 1156 | def test_nonexisting_with_pipes(self):
|
1158 | 1157 | # bpo-30121: Popen with pipes must close properly pipes on error.
|
@@ -2533,7 +2532,7 @@ def test_leak_fast_process_del_killed(self):
|
2533 | 2532 | # let some time for the process to exit, and create a new Popen: this
|
2534 | 2533 | # should trigger the wait() of p
|
2535 | 2534 | time.sleep(0.2)
|
2536 |
| - with self.assertRaises(OSError) as c: |
| 2535 | + with self.assertRaises(OSError): |
2537 | 2536 | with subprocess.Popen(NONEXISTING_CMD,
|
2538 | 2537 | stdout=subprocess.PIPE,
|
2539 | 2538 | stderr=subprocess.PIPE) as proc:
|
@@ -3044,7 +3043,7 @@ def test_communicate_stdin(self):
|
3044 | 3043 | self.assertEqual(proc.returncode, 1)
|
3045 | 3044 |
|
3046 | 3045 | def test_invalid_args(self):
|
3047 |
| - with self.assertRaises((FileNotFoundError, PermissionError)) as c: |
| 3046 | + with self.assertRaises(NONEXISTING_ERRORS): |
3048 | 3047 | with subprocess.Popen(NONEXISTING_CMD,
|
3049 | 3048 | stdout=subprocess.PIPE,
|
3050 | 3049 | stderr=subprocess.PIPE) as proc:
|
|
0 commit comments