The extras added during the call and teardown phases get merged and are displayed in both call and teardown HTML reports
Use this conftest.py file:
import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
pytest_html = item.config.pluginmanager.getplugin("html")
report = outcome.get_result()
extras = getattr(report, "extras", [])
if (
report.when in ("setup", "teardown") and
report.outcome in ('failed', 'skipped')
):
extras.append(pytest_html.extras.html(f'<p>We are in {report.when} phase</p>'))
if report.when == "call":
extras.append(pytest_html.extras.html(f'<p>We are in {report.when} phase</p>'))
report.extras = extras
Use this bug_test.py file:
import pytest
@pytest.fixture
def teardown():
yield
assert False
def test_extras(teardown):
pass
Run the test
Actual result:
The extras for call and teardown are merged and are displayed in both call and teardown reports
Expected result:
- The
call report only displays the extras added during the call phase (<p>We are in call phase</p>)
- The
teardown report only displays the extras added during the teardown phase (<p>We are in teardown phase</p>)
This is a regression. We didn't have this bug in pytest-html==4.0.0
The extras added during the
callandteardownphases get merged and are displayed in bothcallandteardownHTML reportsUse this
conftest.pyfile:Use this
bug_test.pyfile:Run the test
Actual result:
The extras for
callandteardownare merged and are displayed in bothcallandteardownreportsExpected result:
callreport only displays the extras added during thecallphase (<p>We are in call phase</p>)teardownreport only displays the extras added during theteardownphase (<p>We are in teardown phase</p>)This is a regression. We didn't have this bug in
pytest-html==4.0.0