pytest-html icon indicating copy to clipboard operation
pytest-html copied to clipboard

Possibly allowing better extensibility to html output

Open memetb opened this issue 5 years ago • 6 comments
trafficstars

Hi,

I make use of pytest-html extensively and find the plugin generally fantastic.

In my usage, I have resorted to some substantial modifications to the output content. Recently I found myself going a bit too far and running regexes on output to alter them.

I think the following surgical changes would go a long way in avoiding such poor practices:

  • Wrapping body content in a div with class content
  • wrapping header in a div with class summary
  • and wrapping the results in a div with class results

The principal motivation of this would be to allow styling the output.

I think the biggest concern would be whether this will break a bunch of CI tests in the universe that have come to rely on the html output.

I apologize if this is a common request that gets closed repeatedly. I searched around in the issues but didn't find anything specifically asking this.

All three of these changes are trivial to implement and I could easily make a PR on short notice.

memetb avatar Jun 24 '20 12:06 memetb

I'd be happy to review a PR! We can always create a new breaking/major release. 👍 @memetb

BeyondEvil avatar Jun 25 '20 12:06 BeyondEvil

@BeyondEvil I've done a full feature including documentation upate in the PR #311. Let me know if you have any concerns.

Thank you.

memetb avatar Jun 28 '20 09:06 memetb

I just thought that I should add that I’ve developed a plug-in for generating reports using template engines as an alternative for those occasions you find yourself needing to do more heavy customization. It allows you to make a report from scratch or inherit an existing template and override parts of it.

pytest-reporter pytest-reporter-html1

Sorry for the unsolicited advertisement. 🙄

christiansandberg avatar Jun 30 '20 20:06 christiansandberg

Hey, thanks @christiansandberg. That looks quite nice at a glance. I will review it when I get some cycles.

memetb avatar Jul 10 '20 09:07 memetb

maybe a switchable template should be used, instead of hooks/extends.

having the HTML generated via a template engine allowes better readability of output generators and does not need knowledge of python to apply changes of the outcome. see https://www.makotemplates.org/ for example.

if there was a switch to use an own template instead of the shipped one would allow alternative output for everybody.

jkowalleck avatar Nov 28 '20 13:11 jkowalleck

@jkowalleck see my earlier reply for a template based alternative. I also think there is a plan to switch pytest-html to JavaScript which hopefully will allow customization in the future.

christiansandberg avatar Nov 28 '20 14:11 christiansandberg