diff options
author | Gregory P. Smith <greg@krypto.org> | 2017-08-24 21:58:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-24 21:58:25 (GMT) |
commit | 8621bb5d93239316f97281826461b85072ff6db7 (patch) | |
tree | 84335831455c051084816564497bc5b7f549ec83 /Lib/test | |
parent | de50360ac2fec81dbf733f6c3c739b39a8822a39 (diff) | |
download | cpython-8621bb5d93239316f97281826461b85072ff6db7.zip cpython-8621bb5d93239316f97281826461b85072ff6db7.tar.gz cpython-8621bb5d93239316f97281826461b85072ff6db7.tar.bz2 |
bpo-22536: Set the filename in FileNotFoundError. (#3194)
Have the subprocess module set the filename in the FileNotFoundError
exception raised on POSIX systems when the executable or cwd are missing.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_subprocess.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index c24fd1e..ac70597 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1371,6 +1371,16 @@ class ProcessTestCase(BaseTestCase): fds_after_exception = os.listdir(fd_directory) self.assertEqual(fds_before_popen, fds_after_exception) + def test_file_not_found_includes_filename(self): + with self.assertRaises(FileNotFoundError) as c: + subprocess.call(['/opt/nonexistent_binary', 'with', 'some', 'args']) + self.assertEqual(c.exception.filename, '/opt/nonexistent_binary') + + def test_file_not_found_with_bad_cwd(self): + with self.assertRaises(FileNotFoundError) as c: + subprocess.Popen(['exit', '0'], cwd='/some/nonexistent/directory') + self.assertEqual(c.exception.filename, '/some/nonexistent/directory') + class RunFuncTestCase(BaseTestCase): def run_python(self, code, **kwargs): |