Skip to content

Commit cd0ed43

Browse files
authored
fix: Extras from setup/teardown missing in report (#784)
1 parent cfd32d0 commit cd0ed43

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/pytest_html/basereport.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def pytest_terminal_summary(self, terminalreporter):
196196
@pytest.hookimpl(trylast=True)
197197
def pytest_collectreport(self, report):
198198
if report.failed:
199-
self._process_report(report, 0)
199+
self._process_report(report, 0, [])
200200

201201
@pytest.hookimpl(trylast=True)
202202
def pytest_collection_finish(self, session):
@@ -238,16 +238,25 @@ def pytest_runtest_logreport(self, report):
238238
if outcome != "rerun":
239239
test_duration += reports[0].duration
240240

241+
processed_extras = []
242+
for key, reports in self._reports[report.nodeid].items():
243+
when, _ = key
244+
for each in reports:
245+
test_id = report.nodeid
246+
if when != "call":
247+
test_id += f"::{when}"
248+
processed_extras += self._process_extras(each, test_id)
249+
241250
for key, reports in self._reports[report.nodeid].items():
242251
when, _ = key
243252
for each in reports:
244253
dur = test_duration if when == "call" else each.duration
245-
self._process_report(each, dur)
254+
self._process_report(each, dur, processed_extras)
246255

247256
if self._config.getini("generate_report_on_test"):
248257
self._generate_report()
249258

250-
def _process_report(self, report, duration):
259+
def _process_report(self, report, duration, processed_extras):
251260
outcome = _process_outcome(report)
252261
try:
253262
# hook returns as list for some reason
@@ -262,8 +271,9 @@ def _process_report(self, report, duration):
262271
test_id += f"::{report.when}"
263272

264273
data = {
265-
"extras": self._process_extras(report, test_id),
274+
"extras": processed_extras,
266275
}
276+
267277
links = [
268278
extra
269279
for extra in data["extras"]

testing/test_integration.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -518,26 +518,27 @@ def pytest_runtest_makereport(item, call):
518518
)
519519

520520
def test_extra_url(self, pytester):
521-
content = str(random.random())
522521
pytester.makeconftest(
523-
f"""
522+
"""
524523
import pytest
525524
526525
@pytest.hookimpl(hookwrapper=True)
527526
def pytest_runtest_makereport(item, call):
528527
outcome = yield
529528
report = outcome.get_result()
530-
if report.when == 'call':
531-
from pytest_html import extras
532-
report.extras = [extras.url('{content}')]
529+
from pytest_html import extras
530+
report.extras = [extras.url(f'{report.when}')]
533531
"""
534532
)
535533
pytester.makepyfile("def test_pass(): pass")
536534
page = run(pytester)
537535

538-
element = page.select_one("a[class='col-links__extra url']")
539-
assert_that(element.string).is_equal_to("URL")
540-
assert_that(element["href"]).is_equal_to(content)
536+
elements = page.select("a[class='col-links__extra url']")
537+
assert_that(elements).is_length(3)
538+
for each in zip(elements, ["setup", "call", "teardown"]):
539+
element, when = each
540+
assert_that(element.string).is_equal_to("URL")
541+
assert_that(element["href"]).is_equal_to(when)
541542

542543
@pytest.mark.parametrize(
543544
"mime_type, extension",

0 commit comments

Comments
 (0)