diff --git a/changelog/6247.improvement.rst b/changelog/6247.improvement.rst new file mode 100644 index 000000000..6634d6b80 --- /dev/null +++ b/changelog/6247.improvement.rst @@ -0,0 +1 @@ +``--fulltrace`` is honored with collection errors. diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 22c2ce337..33067334c 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -365,12 +365,14 @@ class Collector(Node): def repr_failure(self, excinfo): """ represent a collection failure. """ - if excinfo.errisinstance(self.CollectError): + if excinfo.errisinstance(self.CollectError) and not self.config.getoption( + "fulltrace", False + ): exc = excinfo.value return str(exc.args[0]) # Respect explicit tbstyle option, but default to "short" - # (None._repr_failure_py defaults to "long" without "fulltrace" option). + # (_repr_failure_py uses "long" with "fulltrace" option always). tbstyle = self.config.getoption("tbstyle", "auto") if tbstyle == "auto": tbstyle = "short" diff --git a/testing/python/collect.py b/testing/python/collect.py index 30f9841b5..e036cb7d9 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1210,6 +1210,28 @@ def test_syntax_error_with_non_ascii_chars(testdir): result.stdout.fnmatch_lines(["*ERROR collecting*", "*SyntaxError*", "*1 error in*"]) +def test_collecterror_with_fulltrace(testdir): + testdir.makepyfile("assert 0") + result = testdir.runpytest("--fulltrace") + result.stdout.fnmatch_lines( + [ + "collected 0 items / 1 error", + "", + "*= ERRORS =*", + "*_ ERROR collecting test_collecterror_with_fulltrace.py _*", + "", + "*/_pytest/python.py:*: ", + "_ _ _ _ _ _ _ _ *", + "", + "> assert 0", + "E assert 0", + "", + "test_collecterror_with_fulltrace.py:1: AssertionError", + "*! Interrupted: 1 error during collection !*", + ] + ) + + def test_skip_duplicates_by_default(testdir): """Test for issue https://github.com/pytest-dev/pytest/issues/1609 (#1609)