]> granicus.if.org Git - python/commitdiff
bpo-31178: Mock os.waitpid() in test_subprocess (#3896)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 5 Oct 2017 13:32:53 +0000 (06:32 -0700)
committerGitHub <noreply@github.com>
Thu, 5 Oct 2017 13:32:53 +0000 (06:32 -0700)
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.

Lib/test/test_subprocess.py

index 00dc37bc2c729a32c5d19c2c26fc7ff9527300da..3ba5c028517581ebcc7e8af46969f86369bf4731 100644 (file)
@@ -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))