summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-10-05 14:10:59 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-10-05 14:10:59 (GMT)
commitfae0512e58619231a566bf77aa21148440b0ec8d (patch)
treee4b5c142543f2538a35cdd74f8054be32f011f27 /Lib/test
parentde5427a8f7ce15565d13383bc8d279bb07dda1cb (diff)
downloadcpython-fae0512e58619231a566bf77aa21148440b0ec8d.zip
cpython-fae0512e58619231a566bf77aa21148440b0ec8d.tar.gz
cpython-fae0512e58619231a566bf77aa21148440b0ec8d.tar.bz2
[3.6] bpo-31178: Mock os.waitpid() in test_subprocess (GH-3896) (#3897)3.6
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. (cherry picked from commit 11045c9d8a21dd9bd182a3939189db02815f9783)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_subprocess.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 391d08c..5016513 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1568,8 +1568,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):
@@ -1586,8 +1588,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))