Fix `pytrace=False` and `--tb=line` reports `None` (#10905)
Closes #10831. This fixes a small bug where running tests that contained `pytest.fail(pytrace=False)` with the `--tb=line` flag set results in an output of "None" in the Failures section of the output, and adds a test to ensure the behavior is correct.
This commit is contained in:
parent
4eca6063c8
commit
41f57ef95d
1
AUTHORS
1
AUTHORS
|
@ -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
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Terminal Reporting: Fixed bug when running in ``--tb=line`` mode where ``pytest.fail(pytrace=False)`` tests report ``None``.
|
|
@ -647,7 +647,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.
|
||||||
|
@ -977,9 +977,7 @@ class FormattedExcinfo:
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
reprtraceback = self.repr_traceback(excinfo_)
|
reprtraceback = self.repr_traceback(excinfo_)
|
||||||
reprcrash: Optional[ReprFileLocation] = (
|
reprcrash = excinfo_._getreprcrash()
|
||||||
excinfo_._getreprcrash() if self.style != "value" else None
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# Fallback to native repr if the exception doesn't have a traceback:
|
# Fallback to native repr if the exception doesn't have a traceback:
|
||||||
# ExceptionInfo objects require a full traceback to work.
|
# ExceptionInfo objects require a full traceback to work.
|
||||||
|
|
|
@ -1539,6 +1539,19 @@ 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:
|
||||||
|
p = pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
def test_func1():
|
||||||
|
pytest.fail('test_func1', pytrace=False)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = pytester.runpytest("--tb=line")
|
||||||
|
result.stdout.str()
|
||||||
|
bn = p.name
|
||||||
|
result.stdout.fnmatch_lines(["*%s:3: Failed: test_func1" % bn])
|
||||||
|
|
||||||
def test_pytest_report_header(self, pytester: Pytester, option) -> None:
|
def test_pytest_report_header(self, pytester: Pytester, option) -> None:
|
||||||
pytester.makeconftest(
|
pytester.makeconftest(
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue