fix: Add collections errors to report (#756)
This commit is contained in:
parent
bf19498c5c
commit
cbb3b3982a
|
@ -192,6 +192,11 @@ class BaseReport:
|
|||
f"Generated html report: {self._report_path.as_uri()}",
|
||||
)
|
||||
|
||||
@pytest.hookimpl(trylast=True)
|
||||
def pytest_collectreport(self, report):
|
||||
if report.failed:
|
||||
self._process_report(report, 0)
|
||||
|
||||
@pytest.hookimpl(trylast=True)
|
||||
def pytest_collection_finish(self, session):
|
||||
self._report.collected_items = len(session.items)
|
||||
|
@ -299,7 +304,9 @@ def _format_duration(duration):
|
|||
|
||||
|
||||
def _is_error(report):
|
||||
return report.when in ["setup", "teardown"] and report.outcome == "failed"
|
||||
return (
|
||||
report.when in ["setup", "teardown", "collect"] and report.outcome == "failed"
|
||||
)
|
||||
|
||||
|
||||
def _process_logs(report):
|
||||
|
|
|
@ -133,7 +133,7 @@ class ReportData:
|
|||
self.append_teardown_log(report)
|
||||
|
||||
# passed "setup" and "teardown" are not added to the html
|
||||
if report.when == "call" or (
|
||||
if report.when in ["call", "collect"] or (
|
||||
report.when in ["setup", "teardown"] and report.outcome != "passed"
|
||||
):
|
||||
test_data["log"] = _handle_ansi("\n".join(logs))
|
||||
|
|
|
@ -758,6 +758,20 @@ class TestHTML:
|
|||
assert_that(log).matches(f"- Captured {stream} {when} -")
|
||||
assert_that(log).matches(f"this is {when} {stream}")
|
||||
|
||||
def test_collect_error(self, pytester):
|
||||
error_msg = "Non existent module"
|
||||
pytester.makepyfile(
|
||||
f"""
|
||||
import pytest
|
||||
raise ImportError("{error_msg}")
|
||||
"""
|
||||
)
|
||||
page = run(pytester)
|
||||
assert_results(page, error=1)
|
||||
|
||||
log = get_log(page)
|
||||
assert_that(log).matches(rf"E\s+ImportError: {error_msg}")
|
||||
|
||||
|
||||
class TestLogCapturing:
|
||||
LOG_LINE_REGEX = r"\s+this is {}"
|
||||
|
|
Loading…
Reference in New Issue