Skip to content

Feature Request: Easy use of pytest-html #670

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

Closed
innicoder opened this issue May 10, 2023 · 14 comments
Closed

Feature Request: Easy use of pytest-html #670

innicoder opened this issue May 10, 2023 · 14 comments

Comments

@innicoder
Copy link

innicoder commented May 10, 2023

Part 1

I think there should be an easy way to choose the columns and some way to configure it without actually diving deep because it isn't even working for me.

I think the library should provide a way to configure columns, let's say that we keep the default columns, which are Result, Test, Duration, Link.

I would like to add to an env, just like timestamp, remove link and duration, add result summary (actual error / short version).

Part 2

The other feature I would like to have is instead of Failed or Passed. I'm fine with Passed but I would like to know which Error and outline it in Red for instance..

Instead of Failed, KeyError.


Quick ask if anyone knows, how to add the to the result table (all the solutions didn't work properly like online and docs). Currently I'm looking for adding Error Type to the header and Exception Message (short).

Result Test Duration Links Error Type Summary
Failed TestAcceptance::test_single_case 0.90 KeyError KeyError: 5
@BeyondEvil
Copy link
Contributor

BeyondEvil commented May 10, 2023

First of all, which version are you using?

  1. We have a feature planned where it's easier to configure what columns there should be and in what order. It is however possible to achieve what you're looking to do today.
  2. This is also possible to do today by using the header and row hooks. But you're going to have to parse the report object to find the error.

Feel free to share the code that you've tried so far and maybe we can help you get to a working solution.

@innicoder
Copy link
Author

The header and row hooks documentation is not available online or if you look inside docs, it didn't work for me.

If you tried to do what I wanted with the table I couldn't make it work with the online documentation and information I found. If you try to make the columns I talked about, you will see what I am talking about. There's no easy or hard way to do it.

From the hooks (report) you can't even get the error message and there definitely isn't documentation for this on how to do this..

I'm using the latest version you get when installing pip install pytest-html.

Thanks for the help and the library, it's really great and awesome, there's no package like it and it works really great, this is just some feedback from my side on more advanced topics.

@BeyondEvil
Copy link
Contributor

Please use the new RC: pip install pytest-html==4.0.0rc4

Please share what you have tried so far in code.

The report object is coming from pytest itself, so if there's some information you feel is missing there - you'll have to raise that as an issue with them.

@innicoder
Copy link
Author

Ok I am saying, the example that you have in the readme, doesn't work by default.
It does insert the TD for the row but the header doesn't work.

import pytest


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


def pytest_html_results_table_row(report, cells):
    cells.insert(2, "<td>ATRY</td>")


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.description = str(item.function.__doc__)

@BeyondEvil
Copy link
Contributor

BeyondEvil commented May 16, 2023

What version are you using?

In what way does the header not work? Can you share a screenshot?

@innicoder
Copy link
Author

innicoder commented May 16, 2023 via email

@innicoder
Copy link
Author

@BeyondEvil Any update on the hooks?

@BeyondEvil
Copy link
Contributor

Doing some work on them, but been busy with other stuff the past week.

@innicoder
Copy link
Author

Doing some work on them, but been busy with other stuff the past week.

Ok thanks for the update.

Let me know when they work, I couldn't get it to work with the tables..

@FHanckeEnelion
Copy link

I might have ran into the same problem.

When using normal string:

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

The description column is not created. Instead, it's just sitting there as text:
image
and in the html file it seems that the tags were escaped:
&lt;th&gt;Description&lt;/th&gt;

The only workaround I found so far is to use py.xml library, like so:

from py.xml import html
def pytest_html_results_table_header(cells):
    """Modify report headers for pytest-html.

    This changes three things, in this order:
    1. Change the header 'name' to make it more explicit.
    2. Delete 'links' column.
    3. Insert 'description column'
    """
    cells[1] = html.th("Test name", class_="sortable", col="name")
    del cells[3]
    cells.insert(2, html.th("Description"))

Then everything seems to work fine:
image

Let me know if this is the same case.
OS: Linux Mint 21.1
Python: 3.8.7
pytest: 7.2.0
pytest-html: 3.2.0

@BeyondEvil
Copy link
Contributor

@FHanckeEnelion This is an issue where the documentation (both in repo and on readthedocs) is based off of latest master and not on the latest release.

If you read through this entire issue, you'll see that this is for 4.0.0rc4 and not 3.2.0

@innicoder
Copy link
Author

No, I talked about fully installing it with the specified version 4.0.0rc4 and it wouldn't work properly.

@vlad-ro
Copy link

vlad-ro commented Sep 17, 2024

I'm hitting the same issues with version 4.1.1.

@heqingbluesky
Copy link

yes, I am also experiencing the same issue with version 4.1.1

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

5 participants