pytest-html icon indicating copy to clipboard operation
pytest-html copied to clipboard

Extra in report is duplicated

Open ckmoga opened this issue 2 years ago • 3 comments

import pytest
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    pytest_html = item.config.pluginmanager.getplugin('html')
    outcome = yield
    report = outcome.get_result()
    extra = getattr(report, 'extra', [])
    extra.append(pytest_html.extras.html('<p>Print something</p>'))
    report.extra = extra

In the report, the text is displayed twice:

Print something
Print something

ckmoga avatar Jan 20 '23 07:01 ckmoga

Can you try this with the latest release? 4.0.0rc0

BeyondEvil avatar Mar 05 '23 15:03 BeyondEvil

i found that if you add if report.when == "call": before extra.append, then no dup. though i'm not sure what when == call means. docs

LeiYangGH avatar Apr 26 '23 01:04 LeiYangGH

i found that if you add if report.when == "call": before extra.append, then no dup. though i'm not sure what when == call means. docs

That is correct, to avoid having the append happen multiple you have to add the when == "call" gate (as shown in the docs).

Each test has 3 stages ("when"s), setup, call, and teardown. This is core pytest.

BeyondEvil avatar Apr 26 '23 06:04 BeyondEvil