summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorBo Bayles <bbayles@gmail.com>2018-01-30 06:40:39 (GMT)
committerGregory P. Smith <greg@krypto.org>2018-01-30 06:40:39 (GMT)
commitce0f33d04528fcafc673a8707871f8430d8f7ce8 (patch)
treede60362ad2f3c1bb8af239c1926a7f907887e8c1 /Lib/test/test_subprocess.py
parent95441809ef77a8df5e14601ade6c054ef7114c02 (diff)
downloadcpython-ce0f33d04528fcafc673a8707871f8430d8f7ce8.zip
cpython-ce0f33d04528fcafc673a8707871f8430d8f7ce8.tar.gz
cpython-ce0f33d04528fcafc673a8707871f8430d8f7ce8.tar.bz2
bpo-32102 Add "capture_output=True" to subprocess.run (GH-5149)
Add "capture_output=True" option to subprocess.run, this is equivalent to setting stdout=PIPE, stderr=PIPE but is much more readable.
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index dd63818..eee24bb 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1475,6 +1475,38 @@ class RunFuncTestCase(BaseTestCase):
env=newenv)
self.assertEqual(cp.returncode, 33)
+ def test_capture_output(self):
+ cp = self.run_python(("import sys;"
+ "sys.stdout.write('BDFL'); "
+ "sys.stderr.write('FLUFL')"),
+ capture_output=True)
+ self.assertIn(b'BDFL', cp.stdout)
+ self.assertIn(b'FLUFL', cp.stderr)
+
+ def test_stdout_with_capture_output_arg(self):
+ # run() refuses to accept 'stdout' with 'capture_output'
+ tf = tempfile.TemporaryFile()
+ self.addCleanup(tf.close)
+ with self.assertRaises(ValueError,
+ msg=("Expected ValueError when stdout and capture_output "
+ "args supplied.")) as c:
+ output = self.run_python("print('will not be run')",
+ capture_output=True, stdout=tf)
+ self.assertIn('stdout', c.exception.args[0])
+ self.assertIn('capture_output', c.exception.args[0])
+
+ def test_stderr_with_capture_output_arg(self):
+ # run() refuses to accept 'stderr' with 'capture_output'
+ tf = tempfile.TemporaryFile()
+ self.addCleanup(tf.close)
+ with self.assertRaises(ValueError,
+ msg=("Expected ValueError when stderr and capture_output "
+ "args supplied.")) as c:
+ output = self.run_python("print('will not be run')",
+ capture_output=True, stderr=tf)
+ self.assertIn('stderr', c.exception.args[0])
+ self.assertIn('capture_output', c.exception.args[0])
+
@unittest.skipIf(mswindows, "POSIX specific tests")
class POSIXProcessTestCase(BaseTestCase):