Skip to content

Commit ebebda4

Browse files
authored
Report collection errors in HTML report. (#154)
Fixes #148
1 parent d503176 commit ebebda4

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

pytest_html/plugin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class TestResult:
9696

9797
def __init__(self, outcome, report, logfile, config):
9898
self.test_id = report.nodeid
99-
if report.when != 'call':
99+
if getattr(report, 'when', 'call') != 'call':
100100
self.test_id = '::'.join([report.nodeid, report.when])
101101
self.time = getattr(report, 'duration', 0.0)
102102
self.outcome = outcome
@@ -277,7 +277,7 @@ def append_passed(self, report):
277277
self._appendrow('Passed', report)
278278

279279
def append_failed(self, report):
280-
if report.when == "call":
280+
if getattr(report, 'when', None) == "call":
281281
if hasattr(report, "wasxfail"):
282282
# pytest < 3.0 marked xpasses as failures
283283
self.xpassed += 1
@@ -487,6 +487,10 @@ def pytest_runtest_logreport(self, report):
487487
else:
488488
self.append_other(report)
489489

490+
def pytest_collectreport(self, report):
491+
if report.failed:
492+
self.append_failed(report)
493+
490494
def pytest_sessionstart(self, session):
491495
self.suite_start_time = time.time()
492496

testing/test_pytest_html.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,3 +616,14 @@ def test_fail():
616616
result, html = run(testdir, 'report.html', '--self-contained-html')
617617
assert result.ret
618618
assert 'utf8 longrepr' in html
619+
620+
def test_collect_error(self, testdir):
621+
testdir.makepyfile("""
622+
import xyz
623+
def test_pass(): pass
624+
""")
625+
result, html = run(testdir)
626+
assert result.ret
627+
assert_results(html, tests=0, passed=0, errors=1)
628+
regex_error = '(Import|ModuleNotFound)Error: No module named .*xyz'
629+
assert re.search(regex_error, html) is not None

0 commit comments

Comments
 (0)