Skip to content

Difficulties to remove Links column in the report #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TheoCrd opened this issue Mar 4, 2025 · 5 comments
Open

Difficulties to remove Links column in the report #890

TheoCrd opened this issue Mar 4, 2025 · 5 comments

Comments

@TheoCrd
Copy link

TheoCrd commented Mar 4, 2025

Hello!

I tried to remove the Links column from the report but in vain. Apparently this part of code should do the trick, but as expected it did not work (I do not see a part where the column is removed in this snippet)

@volkan-aslan
Copy link
Contributor

volkan-aslan commented Mar 4, 2025

It looks like the document has changed and it is missing that part as you mentioned. To remove the "Links" column (assuming it is the last column in the table), you can do so as follows:

def pytest_html_results_table_header(cells):
    cells.pop()

def pytest_html_results_table_row(report, cells):
    cells.pop()

@TheoCrd
Copy link
Author

TheoCrd commented Mar 5, 2025

Thank you for your answer!

@TheoCrd
Copy link
Author

TheoCrd commented Mar 6, 2025

Is it also possible to modify the output from the Test column, to avoid having the full path of the test.py file displayed?

Image

@volkan-aslan
Copy link
Contributor

volkan-aslan commented Mar 6, 2025

If console outputs are not important, a basic approach might be to simply change the nodeid as shown below:

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.nodeid = "Any string you want"

However, this would display both the original and given names in the console. That's why I would do it as shown below

1- First create a marker sth like "friendly_name" in pytest.ini

markers =
    friendly_name: friendly name for tests

2- Delete the existed "Test" column and create your own

def pytest_html_results_table_header(cells):
    cells.pop(1)
    cells.insert(1, "<th>Test Name</th>")
    cells.insert(2, "<th>Description</th>")

def pytest_html_results_table_row(report, cells):
    cells.pop(1)
    _friendly_name = getattr(report, "friendly_name", report.nodeid)
    cells.insert(1, f"<td>{_friendly_name}</td>")
    cells.insert(2, f"<td>{report.description}</td>")

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item):
    outcome = yield
    report = outcome.get_result()

    report.description = str(item.function.__doc__)

    # Adding friendly test name information
    marker = [mark for mark in item.iter_markers() if mark.name == "friendly_name"]
    if marker:
        friendly_name = str(marker[0].args[0])
        report.friendly_name = friendly_name

This way, If you add a friendly_name marker to your tests as below, it will be shown as the test name; otherwise, the default test name will be used

@pytest.mark.friendly_name("Test name you want")
def test_example():
    assert True

@TheoCrd
Copy link
Author

TheoCrd commented Mar 10, 2025

Thank you for your answer. I will try it as soon as I can in my project and will return to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants