Skip to content

Commit

Permalink
bpo-31178: Mock os.waitpid() in test_subprocess (python#3896)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner authored Oct 5, 2017
1 parent c1c47c1 commit 11045c9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,8 +1559,10 @@ def proper_error(*args):

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):
Expand All @@ -1577,8 +1579,10 @@ def bad_error(*args):

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))

Expand Down

0 comments on commit 11045c9

Please sign in to comment.