You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to add Plotly graphs in my test report, but they are somehow not visible when I open the report (either Chrome or Edge).
To reproduce, two files need to be created: conftest.py and test_dummy_plot.py. Bellow, the content of those two files, respectively:
importpytestimportpytest_html@pytest.mark.hookwrapperdefpytest_runtest_makereport(item, call):
outcome=yieldreport=outcome.get_result()
ifcall.when=='call':
extras=getattr(report, 'extras', [])
fig=item.user_properties[0]
c=fig.to_html(full_html=False, div_id='my_plot', include_plotlyjs='cdn')
fig.write_html('my_plot.html', include_plotlyjs='cdn') # export the figure to HTML to validate its content (just for debugging).extras.append(pytest_html.extras.html("<div>Additional HTML 1</div>")) # only for debugging.extras.append(pytest_html.extras.html(c))
extras.append(pytest_html.extras.html("<div>Additional HTML 2</div>")) # only for debugging.report.extras=extras
Now, when running the test by invoking python -m pytest --html=report.html --self-contained-html . in the folder containing those two files, two new files are generated:
my_plot.html
report.html
Here is a screenshot of the plot itself, when opening my_plot.html:
And now, a screenshot of the test report, when opening report.html:
We can see that the plot is not rendered, even if present in the HTML file, as depicted in the following screenshot:
I'm not really sure why it is not rendered properly. I raised a question on StackOverflow and it seems that a solution exists, but I don't know how to integrate it properly.
Activity