mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-98966: Handle stdout=subprocess.STDOUT (GH-98967)
Explicitly handle the case where stdout=STDOUT as otherwise the existing error handling gets confused and reports hard to understand errors. Signed-off-by: Paulo Neves <ptsneves@gmail.com>
This commit is contained in:
parent
9654daf793
commit
4abca7e1e7
3 changed files with 12 additions and 0 deletions
|
|
@ -839,6 +839,9 @@ def __init__(self, args, bufsize=-1, executable=None,
|
||||||
if not isinstance(bufsize, int):
|
if not isinstance(bufsize, int):
|
||||||
raise TypeError("bufsize must be an integer")
|
raise TypeError("bufsize must be an integer")
|
||||||
|
|
||||||
|
if stdout is STDOUT:
|
||||||
|
raise ValueError("STDOUT can only be used for stderr")
|
||||||
|
|
||||||
if pipesize is None:
|
if pipesize is None:
|
||||||
pipesize = -1 # Restore default
|
pipesize = -1 # Restore default
|
||||||
if not isinstance(pipesize, int):
|
if not isinstance(pipesize, int):
|
||||||
|
|
|
||||||
|
|
@ -1763,6 +1763,13 @@ def test_capture_output(self):
|
||||||
self.assertIn(b'BDFL', cp.stdout)
|
self.assertIn(b'BDFL', cp.stdout)
|
||||||
self.assertIn(b'FLUFL', cp.stderr)
|
self.assertIn(b'FLUFL', cp.stderr)
|
||||||
|
|
||||||
|
def test_stdout_stdout(self):
|
||||||
|
# run() refuses to accept stdout=STDOUT
|
||||||
|
with self.assertRaises(ValueError,
|
||||||
|
msg=("STDOUT can only be used for stderr")):
|
||||||
|
self.run_python("print('will not be run')",
|
||||||
|
stdout=subprocess.STDOUT)
|
||||||
|
|
||||||
def test_stdout_with_capture_output_arg(self):
|
def test_stdout_with_capture_output_arg(self):
|
||||||
# run() refuses to accept 'stdout' with 'capture_output'
|
# run() refuses to accept 'stdout' with 'capture_output'
|
||||||
tf = tempfile.TemporaryFile()
|
tf = tempfile.TemporaryFile()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
In :mod:`subprocess`, raise a more informative message when
|
||||||
|
``stdout=STDOUT``.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue