From 82753bec50fae4718fc6f38bdab3cf214f2be00f Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 25 Oct 2019 05:59:10 +0200 Subject: [PATCH] terminal: report collection errors as "ERROR" in short summary --- changelog/6059.improvement.rst | 1 + src/_pytest/terminal.py | 8 +++++++- testing/test_terminal.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 changelog/6059.improvement.rst diff --git a/changelog/6059.improvement.rst b/changelog/6059.improvement.rst new file mode 100644 index 000000000..39ffff99b --- /dev/null +++ b/changelog/6059.improvement.rst @@ -0,0 +1 @@ +Collection errors are reported as errors (and not failures like before) in the terminal's short test summary. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 35f6d324b..e9d44f2a8 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -187,7 +187,13 @@ def pytest_report_teststatus(report): letter = "F" if report.when != "call": letter = "f" - return report.outcome, letter, report.outcome.upper() + + # Report failed CollectReports as "error" (in line with pytest_collectreport). + outcome = report.outcome + if report.when == "collect" and outcome == "failed": + outcome = "error" + + return outcome, letter, outcome.upper() @attr.s diff --git a/testing/test_terminal.py b/testing/test_terminal.py index a624be3b4..fdd53d3c6 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1776,3 +1776,20 @@ def test_format_session_duration(seconds, expected): from _pytest.terminal import format_session_duration assert format_session_duration(seconds) == expected + + +def test_collecterror(testdir): + p1 = testdir.makepyfile("raise SyntaxError()") + result = testdir.runpytest("-ra", str(p1)) + result.stdout.fnmatch_lines( + [ + "collected 0 items / 1 errors", + "*= ERRORS =*", + "*_ ERROR collecting test_collecterror.py _*", + "E SyntaxError: *", + "*= short test summary info =*", + "ERROR test_collecterror.py", + "*! Interrupted: 1 errors during collection !*", + "*= 1 error in *", + ] + )