pytest-dev / pytest-dev/pytest-html
ANSI color codes are adding in extra section of report, are not converted in html report
Open
Nobody has claimed this yet.
enhancement
feature
- Dominant language
- Python
- Stars
- 779
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
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)
then html report looks like

and ANSI codes were added as is.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the custom report section shown in conftest.py and trace how that section is rendered in report.html. Reproduce the failure with the provided pytest hook and inspect the generated HTML for raw ANSI codes. Done means ANSI-colored custom sections render correctly in the HTML report without exposing escape sequences.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100