From 4d27b0527410a75a2f45a80e3ac2cb3260d07cc7 Mon Sep 17 00:00:00 2001 From: HolyMagician03-UMich Date: Sat, 6 Apr 2024 18:02:24 -0400 Subject: [PATCH 1/9] resolves issue #11777 --- src/_pytest/terminal.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 973168dc6ff..4d18488eee7 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -1409,7 +1409,10 @@ def _get_line_with_reprcrash_message( pass else: if not running_on_ci(): - available_width = tw.fullwidth - line_width + if config.get_verbosity() >= 2: + available_width = 500 + else: + available_width = tw.fullwidth - line_width msg = _format_trimmed(" - {}", msg, available_width) else: msg = f" - {msg}" From b2587554e3eb97d7b48ffcbba10f532c6f6a1afe Mon Sep 17 00:00:00 2001 From: HolyMagician03-UMich Date: Sat, 6 Apr 2024 18:15:24 -0400 Subject: [PATCH 2/9] modified changelog and AUTHORS --- AUTHORS | 2 ++ changelog/11777.bugfix.rst | 1 + 2 files changed, 3 insertions(+) create mode 100644 changelog/11777.bugfix.rst diff --git a/AUTHORS b/AUTHORS index 53f7a8c2a16..cc054bfd978 100644 --- a/AUTHORS +++ b/AUTHORS @@ -137,6 +137,7 @@ Endre Galaczi Eric Hunsberger Eric Liu Eric Siegerman +Eric Yuan Erik Aronesty Erik Hasse Erik M. Bray @@ -432,6 +433,7 @@ Xixi Zhao Xuan Luong Xuecong Liao Yannick PΓ©roux +Yao Xiao Yoav Caspi Yuliang Shao Yusuke Kadowaki diff --git a/changelog/11777.bugfix.rst b/changelog/11777.bugfix.rst new file mode 100644 index 00000000000..73ebc4152e4 --- /dev/null +++ b/changelog/11777.bugfix.rst @@ -0,0 +1 @@ +Added support for verbosity setting in the short test summary info, so that when -vv is enabled, longer text will be printed out. \ No newline at end of file From 6b65e2345a6df5095747d4be70671f9572572772 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 6 Apr 2024 22:15:44 +0000 Subject: [PATCH 3/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- changelog/11777.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/11777.bugfix.rst b/changelog/11777.bugfix.rst index 73ebc4152e4..d59b153d137 100644 --- a/changelog/11777.bugfix.rst +++ b/changelog/11777.bugfix.rst @@ -1 +1 @@ -Added support for verbosity setting in the short test summary info, so that when -vv is enabled, longer text will be printed out. \ No newline at end of file +Added support for verbosity setting in the short test summary info, so that when -vv is enabled, longer text will be printed out. From 7d361362c69784d4117557879400570dfe53c997 Mon Sep 17 00:00:00 2001 From: HolyMagician03-UMich Date: Sat, 6 Apr 2024 19:13:49 -0400 Subject: [PATCH 4/9] added argument to get_verbosity call --- src/_pytest/terminal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 4d18488eee7..6dd33df25d5 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -1409,7 +1409,7 @@ def _get_line_with_reprcrash_message( pass else: if not running_on_ci(): - if config.get_verbosity() >= 2: + if config.get_verbosity(Config.VERBOSITY_TEST_CASES) >= 2: available_width = 500 else: available_width = tw.fullwidth - line_width From 2061e2968cb005f84879023f1fdb9fe62823a5b9 Mon Sep 17 00:00:00 2001 From: HolyMagician03-UMich Date: Sat, 6 Apr 2024 20:05:24 -0400 Subject: [PATCH 5/9] attempts to fix parameter by explicitly making sure that config is of type Config, defined in pytest. --- src/_pytest/terminal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 6dd33df25d5..f81dd003f06 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -1409,7 +1409,7 @@ def _get_line_with_reprcrash_message( pass else: if not running_on_ci(): - if config.get_verbosity(Config.VERBOSITY_TEST_CASES) >= 2: + if isinstance(config, Config) and config.option.verbose >= 2: available_width = 500 else: available_width = tw.fullwidth - line_width From 14bf4974b5a48e504026cb94905749fedd556d38 Mon Sep 17 00:00:00 2001 From: HolyMagician03-UMich Date: Sun, 7 Apr 2024 10:20:34 -0400 Subject: [PATCH 6/9] adopted suggested changes, made testcase --- changelog/11777.bugfix.rst | 1 - changelog/11777.improvement.rst | 1 + src/_pytest/terminal.py | 11 ++---- testing/test_terminal.py | 69 +++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 8 deletions(-) delete mode 100644 changelog/11777.bugfix.rst create mode 100644 changelog/11777.improvement.rst diff --git a/changelog/11777.bugfix.rst b/changelog/11777.bugfix.rst deleted file mode 100644 index d59b153d137..00000000000 --- a/changelog/11777.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Added support for verbosity setting in the short test summary info, so that when -vv is enabled, longer text will be printed out. diff --git a/changelog/11777.improvement.rst b/changelog/11777.improvement.rst new file mode 100644 index 00000000000..f7fc42b677b --- /dev/null +++ b/changelog/11777.improvement.rst @@ -0,0 +1 @@ +Text is no longer truncated in the ``short test summary info`` section when ``-vv`` is given. \ No newline at end of file diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index f81dd003f06..724d5c54d2f 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -1408,14 +1408,11 @@ def _get_line_with_reprcrash_message( except AttributeError: pass else: - if not running_on_ci(): - if isinstance(config, Config) and config.option.verbose >= 2: - available_width = 500 - else: - available_width = tw.fullwidth - line_width - msg = _format_trimmed(" - {}", msg, available_width) - else: + if running_on_ci() or config.option.verbose >= 2: msg = f" - {msg}" + else: + available_width = tw.fullwidth - line_width + msg = _format_trimmed(" - {}", msg, available_width) if msg is not None: line += msg diff --git a/testing/test_terminal.py b/testing/test_terminal.py index f4942510991..9c17708cc49 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -2443,6 +2443,75 @@ def markup(self, word: str, **markup: str): check("πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", 80, "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰") +def test_short_summary_with_verbose(monkeypatch: MonkeyPatch) -> None: + mocked_verbose_word = "FAILED" + + mocked_pos = "some::nodeid" + + def mock_running_on_ci(): + return False + + def mock_get_pos(*args): + return mocked_pos + + monkeypatch.setattr(_pytest.terminal, "_get_node_id_with_markup", mock_get_pos) + monkeypatch.setattr(_pytest.terminal, "running_on_ci", mock_running_on_ci) + + class Namespace: + def __init__(self, **kwargs): + self.__dict__.update(kwargs) + + class config: + def __init__(self): + object.__setattr__(self, "option", Namespace(verbose=2)) + + class rep: + def _get_verbose_word(self, *args): + return mocked_verbose_word + + class longrepr: + class reprcrash: + pass + + def check(msg, width, expected): + class DummyTerminalWriter: + fullwidth = width + + def markup(self, word: str, **markup: str): + return word + + __tracebackhide__ = True + if msg: + rep.longrepr.reprcrash.message = msg # type: ignore + actual = _get_line_with_reprcrash_message( + config(), # type: ignore[arg-type] + rep(), # type: ignore[arg-type] + DummyTerminalWriter(), # type: ignore[arg-type] + {}, + ) + + assert actual == expected + + # AttributeError with message + check(None, 80, "FAILED some::nodeid") + + check("msg", 80, "FAILED some::nodeid - msg") + check("msg", 3, "FAILED some::nodeid - msg") + + check("some longer msg", 10, "FAILED some::nodeid - some longer msg") + + check("some\nmessage", 25, "FAILED some::nodeid - some\nmessage") + check("some\nmessage", 80, "FAILED some::nodeid - some\nmessage") + + # Test unicode safety. + check("πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", 29, "FAILED some::nodeid - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line") + + # NOTE: constructed, not sure if this is supported. + mocked_pos = "nodeid::πŸ‰::withunicode" + check("πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", 29, "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line") + check("πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", 80, "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line") + + @pytest.mark.parametrize( "seconds, expected", [ From 24372bbdb1ee129eb9992f038f1544dd96dafa5b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 7 Apr 2024 14:20:54 +0000 Subject: [PATCH 7/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- changelog/11777.improvement.rst | 2 +- testing/test_terminal.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/changelog/11777.improvement.rst b/changelog/11777.improvement.rst index f7fc42b677b..fb53c63c10a 100644 --- a/changelog/11777.improvement.rst +++ b/changelog/11777.improvement.rst @@ -1 +1 @@ -Text is no longer truncated in the ``short test summary info`` section when ``-vv`` is given. \ No newline at end of file +Text is no longer truncated in the ``short test summary info`` section when ``-vv`` is given. diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 9c17708cc49..18700d74767 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -2508,8 +2508,16 @@ def markup(self, word: str, **markup: str): # NOTE: constructed, not sure if this is supported. mocked_pos = "nodeid::πŸ‰::withunicode" - check("πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", 29, "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line") - check("πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", 80, "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line") + check( + "πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", + 29, + "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", + ) + check( + "πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", + 80, + "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", + ) @pytest.mark.parametrize( From 0407acbb172df1c2484fb4cf9776c14ef3f35cbf Mon Sep 17 00:00:00 2001 From: HolyMagician03-UMich Date: Sun, 7 Apr 2024 12:49:13 -0400 Subject: [PATCH 8/9] modified config stub in test_line_with_reprcrash to use verbose=0 --- testing/test_terminal.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 9c17708cc49..501867bedd0 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -2377,8 +2377,13 @@ def mock_get_pos(*args): monkeypatch.setattr(_pytest.terminal, "_get_node_id_with_markup", mock_get_pos) + class Namespace: + def __init__(self, **kwargs): + self.__dict__.update(kwargs) + class config: - pass + def __init__(self): + object.__setattr__(self, "option", Namespace(verbose=0)) class rep: def _get_verbose_word(self, *args): @@ -2399,7 +2404,7 @@ def markup(self, word: str, **markup: str): if msg: rep.longrepr.reprcrash.message = msg # type: ignore actual = _get_line_with_reprcrash_message( - config, # type: ignore[arg-type] + config(), # type: ignore[arg-type] rep(), # type: ignore[arg-type] DummyTerminalWriter(), # type: ignore[arg-type] {}, From bb6c58ac028e645650347eccf2b54758de828e38 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 8 Apr 2024 14:37:34 -0300 Subject: [PATCH 9/9] Simplify testing --- testing/test_terminal.py | 104 ++++++++++++--------------------------- 1 file changed, 32 insertions(+), 72 deletions(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 5d88cb62a77..170f1efcf91 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -2383,7 +2383,7 @@ def __init__(self, **kwargs): class config: def __init__(self): - object.__setattr__(self, "option", Namespace(verbose=0)) + self.option = Namespace(verbose=0) class rep: def _get_verbose_word(self, *args): @@ -2448,80 +2448,40 @@ def markup(self, word: str, **markup: str): check("πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", 80, "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰") -def test_short_summary_with_verbose(monkeypatch: MonkeyPatch) -> None: - mocked_verbose_word = "FAILED" - - mocked_pos = "some::nodeid" - - def mock_running_on_ci(): - return False - - def mock_get_pos(*args): - return mocked_pos - - monkeypatch.setattr(_pytest.terminal, "_get_node_id_with_markup", mock_get_pos) - monkeypatch.setattr(_pytest.terminal, "running_on_ci", mock_running_on_ci) - - class Namespace: - def __init__(self, **kwargs): - self.__dict__.update(kwargs) - - class config: - def __init__(self): - object.__setattr__(self, "option", Namespace(verbose=2)) - - class rep: - def _get_verbose_word(self, *args): - return mocked_verbose_word - - class longrepr: - class reprcrash: - pass - - def check(msg, width, expected): - class DummyTerminalWriter: - fullwidth = width - - def markup(self, word: str, **markup: str): - return word - - __tracebackhide__ = True - if msg: - rep.longrepr.reprcrash.message = msg # type: ignore - actual = _get_line_with_reprcrash_message( - config(), # type: ignore[arg-type] - rep(), # type: ignore[arg-type] - DummyTerminalWriter(), # type: ignore[arg-type] - {}, - ) - - assert actual == expected - - # AttributeError with message - check(None, 80, "FAILED some::nodeid") - - check("msg", 80, "FAILED some::nodeid - msg") - check("msg", 3, "FAILED some::nodeid - msg") - - check("some longer msg", 10, "FAILED some::nodeid - some longer msg") - - check("some\nmessage", 25, "FAILED some::nodeid - some\nmessage") - check("some\nmessage", 80, "FAILED some::nodeid - some\nmessage") +def test_short_summary_with_verbose( + monkeypatch: MonkeyPatch, pytester: Pytester +) -> None: + """With -vv do not truncate the summary info (#11777).""" + # On CI we also do not truncate the summary info, monkeypatch it to ensure we + # are testing against the -vv flag on CI. + monkeypatch.setattr(_pytest.terminal, "running_on_ci", lambda: False) - # Test unicode safety. - check("πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", 29, "FAILED some::nodeid - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line") + string_length = 200 + pytester.makepyfile( + f""" + def test(): + s1 = "A" * {string_length} + s2 = "B" * {string_length} + assert s1 == s2 + """ + ) - # NOTE: constructed, not sure if this is supported. - mocked_pos = "nodeid::πŸ‰::withunicode" - check( - "πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", - 29, - "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", + # No -vv, summary info should be truncated. + result = pytester.runpytest() + result.stdout.fnmatch_lines( + [ + "*short test summary info*", + "* assert 'AAA...", + ], ) - check( - "πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", - 80, - "FAILED nodeid::πŸ‰::withunicode - πŸ‰πŸ‰πŸ‰πŸ‰πŸ‰\n2nd line", + + # No truncation with -vv. + result = pytester.runpytest("-vv") + result.stdout.fnmatch_lines( + [ + "*short test summary info*", + f"*{'A' * string_length}*{'B' * string_length}'", + ] )