diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-05-13 01:54:44 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-05-13 01:54:44 (GMT) |
commit | c76358924f5d750460f8693c05987dd866cb9e8a (patch) | |
tree | edfd33c7e4984f84e6696e2bfbc469b37fc3e4c0 /Lib/test/test_subprocess.py | |
parent | 07451ddd4f9db9cfdffdabca360d5873394d305c (diff) | |
download | cpython-c76358924f5d750460f8693c05987dd866cb9e8a.zip cpython-c76358924f5d750460f8693c05987dd866cb9e8a.tar.gz cpython-c76358924f5d750460f8693c05987dd866cb9e8a.tar.bz2 |
Issue #22274: Redirect stderr=STDOUT when stdout not redirected, by Akira Li
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r-- | Lib/test/test_subprocess.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index b5c86f2..9c7aa93 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -504,6 +504,27 @@ class ProcessTestCase(BaseTestCase): tf.seek(0) self.assertStderrEqual(tf.read(), b"strawberry") + def test_stderr_redirect_with_no_stdout_redirect(self): + # test stderr=STDOUT while stdout=None (not set) + + # - grandchild prints to stderr + # - child redirects grandchild's stderr to its stdout + # - the parent should get grandchild's stderr in child's stdout + p = subprocess.Popen([sys.executable, "-c", + 'import sys, subprocess;' + 'rc = subprocess.call([sys.executable, "-c",' + ' "import sys;"' + ' "sys.stderr.write(\'42\')"],' + ' stderr=subprocess.STDOUT);' + 'sys.exit(rc)'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + #NOTE: stdout should get stderr from grandchild + self.assertStderrEqual(stdout, b'42') + self.assertStderrEqual(stderr, b'') # should be empty + self.assertEqual(p.returncode, 0) + def test_stdout_stderr_pipe(self): # capture stdout and stderr to the same pipe p = subprocess.Popen([sys.executable, "-c", |