Closed
Description
I have been able to modify the summary with the following snippet from another issue:
def pytest_html_results_summary(prefix, summary, postfix):
prefix.extend([
html.button("Click me", onclick="myFunction()"),
html.p(id="demo"),
html.script(raw("""
function myFunction() {
document.getElementById('demo').innerHTML = 'Hello World';
}""")),
])
And I am also able to gather the results after the session finishes with:
def pytest_sessionstart(session):
"""
This hook is called at the beginning and creates a placeholder to store all the results of the
session
"""
session.results = dict()
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item):
"""
Write the results of each test in the session
"""
outcome = yield
report = outcome.get_result()
if report.when == "call":
# Save result for later processing in pytest_sessionfinish hook
item.session.results[item] = report
@pytest.hookimpl(tryfirst=True)
def pytest_sessionfinish(session, exitstatus):
"""
This hook runs after all tests are done
"""
print()
print('run status code:', exitstatus)
passed_amount = sum(1 for result in session.results.values() if result.passed)
failed_amount = sum(1 for result in session.results.values() if result.failed)
print(f'there are {passed_amount} passed and {failed_amount} failed tests')
# TODO: Writing this in a file with a link
My problem is that I can not make a connection to write what I have in session finish with what I have in the summary. The summary hook seems to don't have have access to anyinformation of the session.
Furthermore, after making some prints, it seems the summary is generated before executing the pytest_sessionfinish
.
Is there a work around to make my own summary additions after finishing the test?