torsava / rpms / python3

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