From f53b1fa55057a2cece7cde12560a7dfcdfdf0bde Mon Sep 17 00:00:00 2001 From: acjreno Date: Wed, 12 Apr 2023 17:17:02 -0400 Subject: [PATCH] Fix 'None' failure report for tests with pytest.fail(pytrace=False) --- AUTHORS | 1 + src/_pytest/_code/code.py | 2 +- src/_pytest/nodes.py | 2 +- testing/test_terminal.py | 12 ++++++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 1aa5265e6..dee73514a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,6 +13,7 @@ Ahn Ki-Wook Akiomi Kamakura Alan Velasco Alessio Izzo +Alex Jones Alexander Johnson Alexander King Alexei Kozlenok diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 032b83beb..aa953d985 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -627,7 +627,7 @@ class ExceptionInfo(Generic[E]): Ignored if ``style=="native"``. :param str style: - long|short|no|native|value traceback style. + long|short|line|no|native|value traceback style. :param bool abspath: If paths should be changed to absolute or left unchanged. diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index c74740dbc..b9af84c12 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -445,7 +445,7 @@ class Node(metaclass=NodeMeta): if isinstance(excinfo.value, ConftestImportFailure): excinfo = ExceptionInfo.from_exc_info(excinfo.value.excinfo) if isinstance(excinfo.value, fail.Exception): - if not excinfo.value.pytrace: + if not excinfo.value.pytrace and style != "line": style = "value" if isinstance(excinfo.value, FixtureLookupError): return excinfo.value.formatrepr() diff --git a/testing/test_terminal.py b/testing/test_terminal.py index fe325b72d..14a8b3fea 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1539,6 +1539,18 @@ class TestGenericReporting: s = result.stdout.str() assert "def test_func2" not in s + def test_tb_crashline_pytrace_false(self, pytester: Pytester, option) -> None: + pytester.makepyfile( + """ + import pytest + def test_func1(): + pytest.fail('test_func1', pytrace=False) + """ + ) + result = pytester.runpytest("--tb=line") + s = result.stdout.str() + assert "None" not in s + def test_pytest_report_header(self, pytester: Pytester, option) -> None: pytester.makeconftest( """