Open
Description
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)
and ANSI codes were added as is.