Fix 'None' failure report for tests with pytest.fail(pytrace=False)

This commit is contained in:
acjreno 2023-04-12 17:17:02 -04:00
parent 61f7c27ec0
commit f53b1fa550
4 changed files with 15 additions and 2 deletions

View File

@ -13,6 +13,7 @@ Ahn Ki-Wook
Akiomi Kamakura Akiomi Kamakura
Alan Velasco Alan Velasco
Alessio Izzo Alessio Izzo
Alex Jones
Alexander Johnson Alexander Johnson
Alexander King Alexander King
Alexei Kozlenok Alexei Kozlenok

View File

@ -627,7 +627,7 @@ class ExceptionInfo(Generic[E]):
Ignored if ``style=="native"``. Ignored if ``style=="native"``.
:param str style: :param str style:
long|short|no|native|value traceback style. long|short|line|no|native|value traceback style.
:param bool abspath: :param bool abspath:
If paths should be changed to absolute or left unchanged. If paths should be changed to absolute or left unchanged.

View File

@ -445,7 +445,7 @@ class Node(metaclass=NodeMeta):
if isinstance(excinfo.value, ConftestImportFailure): if isinstance(excinfo.value, ConftestImportFailure):
excinfo = ExceptionInfo.from_exc_info(excinfo.value.excinfo) excinfo = ExceptionInfo.from_exc_info(excinfo.value.excinfo)
if isinstance(excinfo.value, fail.Exception): if isinstance(excinfo.value, fail.Exception):
if not excinfo.value.pytrace: if not excinfo.value.pytrace and style != "line":
style = "value" style = "value"
if isinstance(excinfo.value, FixtureLookupError): if isinstance(excinfo.value, FixtureLookupError):
return excinfo.value.formatrepr() return excinfo.value.formatrepr()

View File

@ -1539,6 +1539,18 @@ class TestGenericReporting:
s = result.stdout.str() s = result.stdout.str()
assert "def test_func2" not in s 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: def test_pytest_report_header(self, pytester: Pytester, option) -> None:
pytester.makeconftest( pytester.makeconftest(
""" """