8000 gh-98966: Handle stdout=subprocess.STDOUT by ptsneves · Pull Request #98967 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-98966: Handle stdout=subprocess.STDOUT #98967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,9 @@ def __init__(self, args, bufsize=-1, executable=None,
if not isinstance(bufsize, int):
raise TypeError("bufsize must be an integer")

if stdout is STDOUT:
raise ValueError("STDOUT can only be used for stderr")

if pipesize is None:
pipesize = -1 # Restore default
if not isinstance(pipesize, int):
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,13 @@ def test_capture_output(self):
self.assertIn(b'BDFL', cp.stdout)
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):
# run() refuses to accept 'stdout' with 'capture_output'
tf = tempfile.TemporaryFile()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In :mod:`subprocess`, raise a more informative message when
``stdout=STDOUT``.
0