Skip to content

Commit 11045c9

Browse files
authored
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.
1 parent c1c47c1 commit 11045c9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Lib/test/test_subprocess.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,10 @@ def proper_error(*args):
15591559

15601560
fork_exec.side_effect = proper_error
15611561

1562-
with self.assertRaises(IsADirectoryError):
1563-
self.PopenNoDestructor(["non_existent_command"])
1562+
with mock.patch("subprocess.os.waitpid",
1563+
side_effect=ChildProcessError):
1564+
with self.assertRaises(IsADirectoryError):
1565+
self.PopenNoDestructor(["non_existent_command"])
15641566

15651567
@mock.patch("subprocess._posixsubprocess.fork_exec")
15661568
def test_exception_errpipe_bad_data(self, fork_exec):
@@ -1577,8 +1579,10 @@ def bad_error(*args):
15771579

15781580
fork_exec.side_effect = bad_error
15791581

1580-
with self.assertRaises(subprocess.SubprocessError) as e:
1581-
self.PopenNoDestructor(["non_existent_command"])
1582+
with mock.patch("subprocess.os.waitpid",
1583+
side_effect=ChildProcessError):
1584+
with self.assertRaises(subprocess.SubprocessError) as e:
1585+
self.PopenNoDestructor(["non_existent_command"])
15821586

15831587
self.assertIn(repr(error_data), str(e.exception))
15841588

0 commit comments

Comments
 (0)