How to print test case names in bold letters in pytest report

77 views Asked by At

I am trying to generate an html report for my project showing all the test case names alone in bold letters. I know there is a conftest.py that can be used for customization purposes of html report.

I tried this simple code in conftest.py

def pytest_report_teststatus(report, config):
"""Customize the format of test case names in the pytest report."""
    if report.when == "call":
        test_func = report.nodeid.split("::")[-1]
        bold_test_name = f"\033[1m{test_func}\033[0m"
        config.get_terminal_writer().line(bold_test_name, bold=True)
        report.nodeid = f"\033[1m{test_func}\033[0m"

But this is not printing the test case name in bold. Instead it displays the ascii characters that is present in the above code like this.

[1mtest_001_launch_DTX[0m

Should I use a stylesheet instead? I haven't done this before so any example is much appreciated.

0

There are 0 answers