Skip to content

Commit e034510

Browse files
committed
Respect --fulltrace with collection errors
1 parent 5b3867f commit e034510

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

changelog/6247.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``--fulltrace`` is honored with collection errors.

src/_pytest/nodes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,14 @@ def collect(self):
365365

366366
def repr_failure(self, excinfo):
367367
""" represent a collection failure. """
368-
if excinfo.errisinstance(self.CollectError):
368+
if excinfo.errisinstance(self.CollectError) and not self.config.getoption(
369+
"fulltrace", False
370+
):
369371
exc = excinfo.value
370372
return str(exc.args[0])
371373

372374
# Respect explicit tbstyle option, but default to "short"
373-
# (None._repr_failure_py defaults to "long" without "fulltrace" option).
375+
# (_repr_failure_py uses "long" with "fulltrace" option always).
374376
tbstyle = self.config.getoption("tbstyle", "auto")
375377
if tbstyle == "auto":
376378
tbstyle = "short"

testing/python/collect.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,28 @@ def test_syntax_error_with_non_ascii_chars(testdir):
12101210
result.stdout.fnmatch_lines(["*ERROR collecting*", "*SyntaxError*", "*1 error in*"])
12111211

12121212

1213+
def test_collecterror_with_fulltrace(testdir):
1214+
testdir.makepyfile("assert 0")
1215+
result = testdir.runpytest("--fulltrace")
1216+
result.stdout.fnmatch_lines(
1217+
[
1218+
"collected 0 items / 1 error",
1219+
"",
1220+
"*= ERRORS =*",
1221+
"*_ ERROR collecting test_collecterror_with_fulltrace.py _*",
1222+
"",
1223+
"*/src/_pytest/python.py:*: ",
1224+
"_ _ _ _ _ _ _ _ *",
1225+
"",
1226+
"> assert 0",
1227+
"E assert 0",
1228+
"",
1229+
"test_collecterror_with_fulltrace.py:1: AssertionError",
1230+
"*! Interrupted: 1 error during collection !*",
1231+
]
1232+
)
1233+
1234+
12131235
def test_skip_duplicates_by_default(testdir):
12141236
"""Test for issue https://github.com/pytest-dev/pytest/issues/1609 (#1609)
12151237

0 commit comments

Comments
 (0)