diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-10-05 13:32:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 13:32:53 (GMT) |
commit | 11045c9d8a21dd9bd182a3939189db02815f9783 (patch) | |
tree | 903e5118d74be3c25744c69080f5ceca44283da6 /Lib/test | |
parent | c1c47c166b1012d34f2c6e111ee9ccb5c4d12de7 (diff) | |
download | cpython-11045c9d8a21dd9bd182a3939189db02815f9783.zip cpython-11045c9d8a21dd9bd182a3939189db02815f9783.tar.gz cpython-11045c9d8a21dd9bd182a3939189db02815f9783.tar.bz2 |
bpo-31178: Mock os.waitpid() in test_subprocess (#3896)
Fix test_exception_errpipe_bad_data() and
test_exception_errpipe_normal() of test_subprocess: mock os.waitpid()
to avoid calling the real os.waitpid(0, 0) which is an unexpected
side effect of the test.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_subprocess.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 00dc37b..3ba5c02 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1559,8 +1559,10 @@ class POSIXProcessTestCase(BaseTestCase): fork_exec.side_effect = proper_error - with self.assertRaises(IsADirectoryError): - self.PopenNoDestructor(["non_existent_command"]) + with mock.patch("subprocess.os.waitpid", + side_effect=ChildProcessError): + with self.assertRaises(IsADirectoryError): + self.PopenNoDestructor(["non_existent_command"]) @mock.patch("subprocess._posixsubprocess.fork_exec") def test_exception_errpipe_bad_data(self, fork_exec): @@ -1577,8 +1579,10 @@ class POSIXProcessTestCase(BaseTestCase): fork_exec.side_effect = bad_error - with self.assertRaises(subprocess.SubprocessError) as e: - self.PopenNoDestructor(["non_existent_command"]) + with mock.patch("subprocess.os.waitpid", + side_effect=ChildProcessError): + with self.assertRaises(subprocess.SubprocessError) as e: + self.PopenNoDestructor(["non_existent_command"]) self.assertIn(repr(error_data), str(e.exception)) |