From ea5f445d12721ba28738ccf37bf601853c7f988b Mon Sep 17 00:00:00 2001 From: Eichel Choi Date: Wed, 6 Dec 2023 17:57:52 -0500 Subject: [PATCH 1/6] Used stdio for showcapture to show both stdout and stderr in debugging --- src/_pytest/debugging.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 69ec58c5b8c..51ee6be0f64 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -352,7 +352,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] From 1009e1f75405afb60bc2453dc7fd0ca7f283de65 Mon Sep 17 00:00:00 2001 From: Itamar Hindi Date: Wed, 6 Dec 2023 18:49:47 -0500 Subject: [PATCH 2/6] Added stdio checker --- testing/test_terminal.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 596c3c67ede..05f37a9ab88 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1620,6 +1620,11 @@ def test_one(): 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 From c49e906cc3b49fc6e83610d02a3bf44e2c79f534 Mon Sep 17 00:00:00 2001 From: Itamar Hindi Date: Wed, 6 Dec 2023 18:54:08 -0500 Subject: [PATCH 3/6] Added additional testing to confirm stdout and stderr in result and not log --- testing/test_terminal.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 05f37a9ab88..1473d6e750f 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1665,6 +1665,11 @@ def test_func(): 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 From 0cb5ac389faab20233f7bcaa3727cf4b03ab876d Mon Sep 17 00:00:00 2001 From: Itamar Hindi Date: Wed, 6 Dec 2023 19:05:09 -0500 Subject: [PATCH 4/6] Added an update in changelog for the new feature --- changelog/11037.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/11037.feature.rst diff --git a/changelog/11037.feature.rst b/changelog/11037.feature.rst new file mode 100644 index 00000000000..434381e7643 --- /dev/null +++ b/changelog/11037.feature.rst @@ -0,0 +1 @@ +Added stdio as option for --show-capture to have both stderr and stdout output together. From be0d6e49d932a613419b96f3da867ea1f9f310d8 Mon Sep 17 00:00:00 2001 From: Eichel Choi Date: Wed, 6 Dec 2023 19:02:14 -0500 Subject: [PATCH 5/6] Included stdio in choices under Group._addoption to have stdio display both stdout and stderr. --- src/_pytest/terminal.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index ea26d9368dc..02b7d1b6051 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -217,9 +217,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( @@ -1039,7 +1039,14 @@ def print_teardown_sections(self, rep: TestReport) -> None: 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) @@ -1085,7 +1092,14 @@ def _outrep_summary(self, rep: BaseReport) -> None: 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": From 7c0465009422a5f90b23039996d97fdb8c7bea67 Mon Sep 17 00:00:00 2001 From: Itamar Hindi Date: Wed, 6 Dec 2023 19:19:03 -0500 Subject: [PATCH 6/6] Added author names --- AUTHORS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 669ec537e56..c579016ba16 100644 --- a/AUTHORS +++ b/AUTHORS @@ -173,6 +173,7 @@ Ilya Konstantinov Ionuț Turturică Isaac Virshup Israel Fruchter +Itamar Hindi Itxaso Aizpurua Iwan Briquemont Jaap Broekhuizen @@ -347,6 +348,7 @@ Sanket Duthade Sankt Petersbug Saravanan Padmanaban Sean Malloy +Sebin (Eichel) Choi Segev Finer Serhii Mozghovyi Seth Junot