Skip to content

[3.6] bpo-32667: Fix tests when $PATH contains a file (GH-5322) #5323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_dtrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def assert_usable(self):
try:
output = self.trace(abspath("assert_usable" + self.EXTENSION))
output = output.strip()
except (FileNotFoundError, PermissionError) as fnfe:
except (FileNotFoundError, NotADirectoryError, PermissionError) as fnfe:
output = str(fnfe)
if output != "probe: success":
raise unittest.SkipTest(
Expand Down
15 changes: 7 additions & 8 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
SETBINARY = ''

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


class BaseTestCase(unittest.TestCase):
Expand Down Expand Up @@ -310,9 +312,9 @@ def test_executable_takes_precedence(self):
# 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):
Expand Down Expand Up @@ -1150,13 +1152,10 @@ def test_leaking_fds_on_error(self):
# 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.
Expand Down Expand Up @@ -2539,7 +2538,7 @@ def test_leak_fast_process_del_killed(self):
# 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:
Expand Down Expand Up @@ -2978,7 +2977,7 @@ def test_communicate_stdin(self):
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:
Expand Down