Skip to content

Commit b31206a

Browse files
authored
bpo-32667: Fix tests when $PATH contains a file (#5322)
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.
1 parent 93a6119 commit b31206a

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Lib/test/test_dtrace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def assert_usable(self):
7979
try:
8080
output = self.trace(abspath("assert_usable" + self.EXTENSION))
8181
output = output.strip()
82-
except (FileNotFoundError, PermissionError) as fnfe:
82+
except (FileNotFoundError, NotADirectoryError, PermissionError) as fnfe:
8383
output = str(fnfe)
8484
if output != "probe: success":
8585
raise unittest.SkipTest(

Lib/test/test_subprocess.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
SETBINARY = ''
4747

4848
NONEXISTING_CMD = ('nonexisting_i_hope',)
49+
# Ignore errors that indicate the command was not found
50+
NONEXISTING_ERRORS = (FileNotFoundError, NotADirectoryError, PermissionError)
4951

5052

5153
class BaseTestCase(unittest.TestCase):
@@ -306,9 +308,9 @@ def test_executable_takes_precedence(self):
306308
# Verify first that the call succeeds without the executable arg.
307309
pre_args = [sys.executable, "-c"]
308310
self._assert_python(pre_args)
309-
self.assertRaises((FileNotFoundError, PermissionError),
311+
self.assertRaises(NONEXISTING_ERRORS,
310312
self._assert_python, pre_args,
311-
executable="doesnotexist")
313+
executable=NONEXISTING_CMD[0])
312314

313315
@unittest.skipIf(mswindows, "executable argument replaces shell")
314316
def test_executable_replaces_shell(self):
@@ -1146,13 +1148,10 @@ def test_leaking_fds_on_error(self):
11461148
# value for that limit, but Windows has 2048, so we loop
11471149
# 1024 times (each call leaked two fds).
11481150
for i in range(1024):
1149-
with self.assertRaises(OSError) as c:
1151+
with self.assertRaises(NONEXISTING_ERRORS):
11501152
subprocess.Popen(NONEXISTING_CMD,
11511153
stdout=subprocess.PIPE,
11521154
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
11561155

11571156
def test_nonexisting_with_pipes(self):
11581157
# bpo-30121: Popen with pipes must close properly pipes on error.
@@ -2533,7 +2532,7 @@ def test_leak_fast_process_del_killed(self):
25332532
# let some time for the process to exit, and create a new Popen: this
25342533
# should trigger the wait() of p
25352534
time.sleep(0.2)
2536-
with self.assertRaises(OSError) as c:
2535+
with self.assertRaises(OSError):
25372536
with subprocess.Popen(NONEXISTING_CMD,
25382537
stdout=subprocess.PIPE,
25392538
stderr=subprocess.PIPE) as proc:
@@ -3044,7 +3043,7 @@ def test_communicate_stdin(self):
30443043
self.assertEqual(proc.returncode, 1)
30453044

30463045
def test_invalid_args(self):
3047-
with self.assertRaises((FileNotFoundError, PermissionError)) as c:
3046+
with self.assertRaises(NONEXISTING_ERRORS):
30483047
with subprocess.Popen(NONEXISTING_CMD,
30493048
stdout=subprocess.PIPE,
30503049
stderr=subprocess.PIPE) as proc:

0 commit comments

Comments
 (0)