Skip to content

ANSI color codes are adding in extra section of report, are not converted in html report #332

Open
@heaventud

Description

@heaventud

Use case:
I want to add custom section in pytest report and color it by red.

Implementation:
conftest.py:

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    if (report.when == "call" or report.when == 'teardown') and report.failed:
        config = item.funcargs.get('config')
        if config is not None:
            artifacts_dir = config.get('artifacts_folder', '<ARTIFACTS_DIR>')
        else:
            config = sys.modules.get("config")
            artifacts_dir = getattr(config, 'results_dir', '<ARTIFACTS_DIR>')
        filepath = str(item.fspath).rsplit('tests')[1].lstrip('/')
        test_path = os.path.join(filepath, str(item.name))
        summary = """
Test failed: {test_path}
See artifacts in:
    (ansible run) {artifacts_folder}/{test_path}
        or   {artifacts_folder}/report.html
    (Teamcity run) Artifacts tab --> *.tar.gz/{test_path}
        or   Artifacts tab --> *.tar.gz/report.html
""".format(test_path=test_path, artifacts_folder=artifacts_dir)
        report.longrepr.addsection("Details", summary)

then html report looks like
2020-08-25_14-40-07

and ANSI codes were added as is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue/PR relates to a feature request.featureThis issue/PR relates to a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions