Skip to content

Commit

Permalink
_repr_failure_py: ignore pytrace=False with --full-trace (#140)
Browse files Browse the repository at this point in the history
Alternative / related to pytest-dev#6232.
This is in line with pytest-dev#6247.
  • Loading branch information
blueyed authored Nov 26, 2019
1 parent 6ad9d99 commit 140d256
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,16 @@ def _prunetraceback(self, excinfo):
def _repr_failure_py(
self, excinfo: ExceptionInfo[Union[Failed, FixtureLookupError]], style=None
) -> Union[str, ReprExceptionInfo, ExceptionChainRepr, FixtureLookupErrorRepr]:
if isinstance(excinfo.value, Failed):
if not excinfo.value.pytrace:
return str(excinfo.value)
fulltrace = self.config.getoption("fulltrace", False)
if (
not fulltrace
and isinstance(excinfo.value, Failed)
and not excinfo.value.pytrace
):
return str(excinfo.value)
if isinstance(excinfo.value, FixtureLookupError):
return excinfo.value.formatrepr()
if self.config.getoption("fulltrace", False):
if fulltrace:
style = "long"
else:
self._prunetraceback(excinfo)
Expand Down
11 changes: 11 additions & 0 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,17 @@ def teardown_function(function):
result.stdout.fnmatch_lines(["world", "hello"])
result.stdout.no_fnmatch_line("*def teardown_function*")

# But with --full-trace.
result = testdir.runpytest("--fulltrace")
result.stdout.fnmatch_lines(
[
"*def teardown_function*",
"E Failed: world",
"E Failed: hello",
"*= 1 failed, 1 error in *",
]
)


def test_pytest_fail_notrace_collection(testdir):
"""Test pytest.fail(..., pytrace=False) does not show tracebacks during collection."""
Expand Down

0 comments on commit 140d256

Please sign in to comment.