Skip to content

Difficulties to remove Links column in the report #890

Open

Description

@TheoCrd

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)

Activity

  1. volkan-aslan commented on Mar 4, 2025

    @volkan-aslan
    Contributor

    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()
    
  2. TheoCrd commented on Mar 5, 2025

    @TheoCrd
    Author

    Thank you for your answer!

  3. TheoCrd commented on Mar 6, 2025

    @TheoCrd
    Author

    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

  4. volkan-aslan commented on Mar 6, 2025

    @volkan-aslan
    Contributor

    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
    
  5. TheoCrd commented on Mar 10, 2025

    @TheoCrd
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions