@@ -504,6 +504,27 @@ def test_stderr_fileobj(self):
504504 tf .seek (0 )
505505 self .assertStderrEqual (tf .read (), b"strawberry" )
506506
507+ def test_stderr_redirect_with_no_stdout_redirect (self ):
508+ # test stderr=STDOUT while stdout=None (not set)
509+
510+ # - grandchild prints to stderr
511+ # - child redirects grandchild's stderr to its stdout
512+ # - the parent should get grandchild's stderr in child's stdout
513+ p = subprocess .Popen ([sys .executable , "-c" ,
514+ 'import sys, subprocess;'
515+ 'rc = subprocess.call([sys.executable, "-c",'
516+ ' "import sys;"'
517+ ' "sys.stderr.write(\' 42\' )"],'
518+ ' stderr=subprocess.STDOUT);'
519+ 'sys.exit(rc)' ],
520+ stdout = subprocess .PIPE ,
521+ stderr = subprocess .PIPE )
522+ stdout , stderr = p .communicate ()
523+ #NOTE: stdout should get stderr from grandchild
524+ self .assertStderrEqual (stdout , b'42' )
525+ self .assertStderrEqual (stderr , b'' ) # should be empty
526+ self .assertEqual (p .returncode , 0 )
527+
507528 def test_stdout_stderr_pipe (self ):
508529 # capture stdout and stderr to the same pipe
509530 p = subprocess .Popen ([sys .executable , "-c" ,
0 commit comments