Skip to content

Commit

Permalink
CollectError.repr_failure: honor explicit tbstyle option
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Mar 23, 2019
1 parent 15d6088 commit aa205f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,14 @@ def repr_failure(self, excinfo):
if excinfo.errisinstance(self.CollectError):
exc = excinfo.value
return str(exc.args[0])
return self._repr_failure_py(excinfo, style="short")

# Respect explicit tbstyle option, but default to "short"
# (None._repr_failure_py defaults to "long" without "fulltrace" option).
tbstyle = self.config.getoption("tbstyle")
if tbstyle == "auto":
tbstyle = "short"

return self._repr_failure_py(excinfo, style=tbstyle)

def _prunetraceback(self, excinfo):
if hasattr(self, "fspath"):
Expand Down
10 changes: 10 additions & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import pytest
from _pytest.main import _in_venv
from _pytest.main import EXIT_INTERRUPTED
from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.main import Session

Expand Down Expand Up @@ -1234,3 +1235,12 @@ def test_collect_sub_with_symlinks(use_pkg, testdir):
"*2 passed in*",
]
)


def test_collector_respects_tbstyle(testdir):
p1 = testdir.makepyfile("assert 0")
result = testdir.runpytest(p1, "--tb=native")
assert result.ret == EXIT_INTERRUPTED
result.stdout.fnmatch_lines(
["Traceback (most recent call last):", "AssertionError: assert 0"]
)

0 comments on commit aa205f7

Please sign in to comment.