47069f
From 54849962eacc38f4e6c6f8a72ae258b3e7c2ecd5 Mon Sep 17 00:00:00 2001
47069f
From: Victor Stinner <victor.stinner@gmail.com>
47069f
Date: Thu, 5 Oct 2017 15:05:30 +0200
47069f
Subject: [PATCH] bpo-31178: Mock os.waitpid() in test_subprocess
47069f
47069f
Fix test_exception_errpipe_bad_data() and
47069f
test_exception_errpipe_normal() of test_subprocess: mock os.waitpid()
47069f
to avoid calling the real os.waitpid(0, 0) which is an unexpected
47069f
side effect of the test.
47069f
---
47069f
 Lib/test/test_subprocess.py | 12 ++++++++----
47069f
 1 file changed, 8 insertions(+), 4 deletions(-)
47069f
47069f
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
47069f
index 00dc37bc2c7..3ba5c028517 100644
47069f
--- a/Lib/test/test_subprocess.py
47069f
+++ b/Lib/test/test_subprocess.py
47069f
@@ -1559,8 +1559,10 @@ def proper_error(*args):
47069f
 
47069f
         fork_exec.side_effect = proper_error
47069f
 
47069f
-        with self.assertRaises(IsADirectoryError):
47069f
-            self.PopenNoDestructor(["non_existent_command"])
47069f
+        with mock.patch("subprocess.os.waitpid",
47069f
+                        side_effect=ChildProcessError):
47069f
+            with self.assertRaises(IsADirectoryError):
47069f
+                self.PopenNoDestructor(["non_existent_command"])
47069f
 
47069f
     @mock.patch("subprocess._posixsubprocess.fork_exec")
47069f
     def test_exception_errpipe_bad_data(self, fork_exec):
47069f
@@ -1577,8 +1579,10 @@ def bad_error(*args):
47069f
 
47069f
         fork_exec.side_effect = bad_error
47069f
 
47069f
-        with self.assertRaises(subprocess.SubprocessError) as e:
47069f
-            self.PopenNoDestructor(["non_existent_command"])
47069f
+        with mock.patch("subprocess.os.waitpid",
47069f
+                        side_effect=ChildProcessError):
47069f
+            with self.assertRaises(subprocess.SubprocessError) as e:
47069f
+                self.PopenNoDestructor(["non_existent_command"])
47069f
 
47069f
         self.assertIn(repr(error_data), str(e.exception))
47069f