Skip to content

HTML extras for 'call' and 'teardown' phases get merged #1077

Description

@harmin-parra

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

Image

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions