[Python-checkins] closes bpo-32490: Fix filename duplication in subprocess exception message. (GH-9163)
Benjamin Peterson
webhook-mailer at python.org
Tue Sep 11 11:54:10 EDT 2018
https://github.com/python/cpython/commit/73870bfeb9cf350d84ee88bd25430c104b3c6191
commit: 73870bfeb9cf350d84ee88bd25430c104b3c6191
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: Benjamin Peterson <benjamin at python.org>
date: 2018-09-11T08:54:07-07:00
summary:
closes bpo-32490: Fix filename duplication in subprocess exception message. (GH-9163)
8621bb5d93239316f97281826461b85072ff6db7 sets the filename in directly in the FileNotFoundError, so we may revert the earlier fix 5f780400572508a8179de6a6c13b58b7be417ef5.
files:
A Misc/NEWS.d/next/Library/2018-09-11-01-25-35.bpo-32490.ROIDO1.rst
M Lib/subprocess.py
M Lib/test/test_subprocess.py
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 1e04d5e57013..c827113a933f 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1512,8 +1512,6 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
err_filename = orig_executable
if errno_num != 0:
err_msg = os.strerror(errno_num)
- if errno_num == errno.ENOENT:
- err_msg += ': ' + repr(err_filename)
raise child_exception_type(errno_num, err_msg, err_filename)
raise child_exception_type(err_msg)
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 8419061b2a90..c56e1b632150 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1520,7 +1520,6 @@ def _get_chdir_exception(self):
# string and instead capture the exception that we want to see
# below for comparison.
desired_exception = e
- desired_exception.strerror += ': ' + repr(self._nonexistent_dir)
else:
self.fail("chdir to nonexistent directory %s succeeded." %
self._nonexistent_dir)
@@ -1537,6 +1536,7 @@ def test_exception_cwd(self):
# it up to the parent process as the correct exception.
self.assertEqual(desired_exception.errno, e.errno)
self.assertEqual(desired_exception.strerror, e.strerror)
+ self.assertEqual(desired_exception.filename, e.filename)
else:
self.fail("Expected OSError: %s" % desired_exception)
@@ -1551,6 +1551,7 @@ def test_exception_bad_executable(self):
# it up to the parent process as the correct exception.
self.assertEqual(desired_exception.errno, e.errno)
self.assertEqual(desired_exception.strerror, e.strerror)
+ self.assertEqual(desired_exception.filename, e.filename)
else:
self.fail("Expected OSError: %s" % desired_exception)
@@ -1564,6 +1565,7 @@ def test_exception_bad_args_0(self):
# it up to the parent process as the correct exception.
self.assertEqual(desired_exception.errno, e.errno)
self.assertEqual(desired_exception.strerror, e.strerror)
+ self.assertEqual(desired_exception.filename, e.filename)
else:
self.fail("Expected OSError: %s" % desired_exception)
diff --git a/Misc/NEWS.d/next/Library/2018-09-11-01-25-35.bpo-32490.ROIDO1.rst b/Misc/NEWS.d/next/Library/2018-09-11-01-25-35.bpo-32490.ROIDO1.rst
new file mode 100644
index 000000000000..16fe7b4d4c09
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-09-11-01-25-35.bpo-32490.ROIDO1.rst
@@ -0,0 +1,2 @@
+Prevent filename duplication in :mod:`subprocess` exception messages. Patch
+by Zackery Spytz.
More information about the Python-checkins
mailing list