Skip to content

Customizable html output structure #311

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

Conversation

memetb
Copy link

@memetb memetb commented Jun 27, 2020

Following up on #310, I've made a basic modification to the html structure and how it is generated.

I also added a new hook called pytest_html_report_final_dom, the semantics of which are fairly straightforward.

Commit e8bd795 in itself would be sufficient for addressesing issue #310. Commit 8c97045 is an added bonus to make life easier.

I would also recommend that perhaps in the future, a migration away from py.xml.html might be beneficial (in favor of core python libraries that support native tree walking etc). The py package is noted as being in maintenance mode and new projects are recommended not to be started using that library.

Given that the changes required to upgrade pytest-html are actually somewhat limited, it might be a good migration target for the future.

Please let me know if or how I should amend this PR to meet project guidelines.

content will be created with the following document structure:
 body
   .content
     .content-header
       h1
       .content-environment
       .content-summary
     .content-results #results-container

Javascript for dealing with table interactivity has been updated to use
container id instead of relying on appending as final element of body.
@memetb memetb force-pushed the customizable-html-output-structure branch from b71bbf9 to 8c97045 Compare June 27, 2020 13:38
@memetb
Copy link
Author

memetb commented Jun 27, 2020

I might need some help with the npm/grunt tests.

Also, I'm seeing 45 tests failing on master.

Comments?

@memetb memetb force-pushed the customizable-html-output-structure branch from 25b83e2 to efa8c40 Compare June 28, 2020 09:35
@BeyondEvil
Copy link
Contributor

This is really nice work @memetb ! 💪

I would really like @ssbarnea input on this as well. 😊

I would also recommend that perhaps in the future, a migration away from py.xml.html might be beneficial (in favor of core python libraries that support native tree walking etc). The py package is noted as being in maintenance mode and new projects are recommended not to be started using that library.

Yes, I agree 100% and it's been on my ToDo for a long time - I just have not had the time. :(

Are there core python libraries that support HTML natively?

@memetb
Copy link
Author

memetb commented Jun 28, 2020

Thanks. Much appreciated.

With regards to html libraries: I really like the whole html.div( blah blah ) verbosity as a library consumer, i.e. when I just want to quickly spit out some html. However, as a library provider, I think the most important thing should be walkability/visitability.

So very high up on my list of requirements for that document variable that's passed to the hook is that I could use an xpath query on it.

To that effect, the xml module that comes stock with python is pretty powerful.

I can take that document object as it currently is and simply do:

import xml.etree.ElementTree as ET 
doc = ET.fromstring(document.unicode())
doc.findall(".//div") # xpath query

To output from an element tree, one would have to do an io.ByteBuffer to get a string, or can simply call:

ET.ElementTree(doc).write( filename )

The weakness of ElementTree comes from the building of the tree (it's not as neat and easy as py.xml), but I think that's a bullet we can bite as a library provider.

@BeyondEvil
Copy link
Contributor

Thanks. Much appreciated.

With regards to html libraries: I really like the whole html.div( blah blah ) verbosity as a library consumer, i.e. when I just want to quickly spit out some html. However, as a library provider, I think the most important thing should be walkability/visitability.

So very high up on my list of requirements for that document variable that's passed to the hook is that I could use an xpath query on it.

To that effect, the xml module that comes stock with python is pretty powerful.

I can take that document object as it currently is and simply do:

import xml.etree.ElementTree as ET 
doc = ET.fromstring(document.unicode())
doc.findall(".//div") # xpath query

To output from an element tree, one would have to do an io.ByteBuffer to get a string, or can simply call:

ET.ElementTree(doc).write( filename )

The weakness of ElementTree comes from the building of the tree (it's not as neat and easy as py.xml), but I think that's a bullet we can bite as a library provider.

Interesting! 🤔

@memetb
Copy link
Author

memetb commented Jun 29, 2020

@BeyondEvil: I've been dogfooding this addition, and I think the hook for the dom finalizer should include a session parameter to avoid ugly globals. I will add a final commit to this affect.

@memetb
Copy link
Author

memetb commented Jul 7, 2020

@BeyondEvil , @ssbarnea: any notes or comments on this PR?

@ssbarnea
Copy link
Member

@memetb Please resolve conflicts.

@memetb
Copy link
Author

memetb commented Aug 12, 2020

@ssbarnea: Merge is done, however I'll have to check what has changed since I wrote this. evidently something no longer passes the node test.

@memetb
Copy link
Author

memetb commented Aug 17, 2020

Fellas, (@ssbarnea, @BeyondEvil) I'm at a loss for what's going wrong here.

The show_hide_extras test is opaque to me in what it's trying to do, and it isn't my code. I actually don't see how it's even related to the code in this branch given that it finds the element based on class name ('.passed'). (I guess I understand that it's looking at the collapsed status and toggling it, however I don't understand the design intent of using .firstElementChild.firstElementChild given the DOM, and this seems to be what is failing.)

Likewise, the sort_column_test error I'm seeing is seemingly unrelated to this revision.

A second pair of eyes would be appreciated here.

@ssbarnea ssbarnea added the feature This issue/PR relates to a feature request. label Aug 23, 2020
@BeyondEvil
Copy link
Contributor

BeyondEvil commented Nov 4, 2023

As the plugin has seen major rework in v4, I'm not sure how relevant this is anymore.

If you the reader want to contribute with something here, please feel free to reopen.

@BeyondEvil BeyondEvil closed this Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants