This commit is contained in:
ihindi1111 2024-06-18 18:00:47 +02:00 committed by GitHub
commit 0347346461
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 5 deletions

View File

@ -185,6 +185,7 @@ Ilya Konstantinov
Ionuț Turturică
Isaac Virshup
Israel Fruchter
Itamar Hindi
Itxaso Aizpurua
Iwan Briquemont
Jaap Broekhuizen
@ -371,6 +372,7 @@ Sanket Duthade
Sankt Petersbug
Saravanan Padmanaban
Sean Malloy
Sebin (Eichel) Choi
Segev Finer
Serhii Mozghovyi
Seth Junot

View File

@ -0,0 +1 @@
Added stdio as option for --show-capture to have both stderr and stdout output together.

View File

@ -348,7 +348,13 @@ def _enter_pdb(
("stderr", rep.capstderr),
("log", rep.caplog),
):
if showcapture in (sectionname, "all") and content:
if (
showcapture in (sectionname, "all")
or (
showcapture == "stdio"
and ("stdout" in sectionname or "stderr" in sectionname)
)
) and content:
tw.sep(">", "captured " + sectionname)
if content[-1:] == "\n":
content = content[:-1]

View File

@ -227,9 +227,9 @@ def pytest_addoption(parser: Parser) -> None:
"--show-capture",
action="store",
dest="showcapture",
choices=["no", "stdout", "stderr", "log", "all"],
choices=["no", "stdout", "stderr", "log", "stdio", "all"],
default="all",
help="Controls how captured stdout/stderr/log is shown on failed tests. "
help="Controls how captured stdout/stderr/log is shown on failed tests. stdio displays both stdout and stderr. "
"Default: all.",
)
group._addoption(
@ -1084,7 +1084,14 @@ class TerminalReporter:
if showcapture == "no":
return
for secname, content in rep.sections:
if showcapture != "all" and showcapture not in secname:
if (
showcapture != "all"
and showcapture not in secname
and (
showcapture != "stdio"
or ("stderr" not in secname and "stdout" not in secname)
)
):
continue
if "teardown" in secname:
self._tw.sep("-", secname)
@ -1147,7 +1154,14 @@ class TerminalReporter:
if showcapture == "no":
return
for secname, content in rep.sections:
if showcapture != "all" and showcapture not in secname:
if (
showcapture != "all"
and showcapture not in secname
and (
showcapture != "stdio"
or ("stderr" not in secname and "stdout" not in secname)
)
):
continue
self._tw.sep("-", secname)
if content[-1:] == "\n":

View File

@ -1611,6 +1611,11 @@ def pytest_report_header(config, start_path):
assert "!This is stderr!" not in stdout
assert "!This is a warning log msg!" in stdout
stdout = pytester.runpytest("--show-capture=stdio", "--tb=short").stdout.str()
assert "!This is stdout!" in stdout
assert "!This is stderr!" in stdout
assert "!This is a warning log msg!" not in stdout
stdout = pytester.runpytest("--show-capture=no", "--tb=short").stdout.str()
assert "!This is stdout!" not in stdout
assert "!This is stderr!" not in stdout
@ -1651,6 +1656,11 @@ def pytest_report_header(config, start_path):
assert "!stderr!" not in result
assert "!log!" in result
result = pytester.runpytest("--show-capture=stdio", "--tb=short").stdout.str()
assert "!stdout!" in result
assert "!stderr!" in result
assert "!log!" not in result
result = pytester.runpytest("--show-capture=no", "--tb=short").stdout.str()
assert "!stdout!" not in result
assert "!stderr!" not in result