pytest-dev / pytest-html

Plugin for generating HTML reports for pytest results
Other
689 stars 234 forks source link

Gathering some test run statistics at the end of the test run and displaying them in summary section #534

Open MartykQ opened 2 years ago

MartykQ commented 2 years ago

Hi all!

I have a situation where I do some REST API calls during pytest run. Each request is saved in DB with the session_id field which is either some random uuid generated in session scoped fixture or testrun_uid fixture from pytest-xdist

At the end of the session I would like to query my database that holds all needed data and gather some statistics, for example, a number of made requests/average response time and display it in the summary section.

I was thinking of using

def pytest_html_results_summary(prefix, summary, postfix):
    """Called before adding the summary section to the report"""

but the issue is there is no access to my session id fixture from there.

Has somebody faced the similar issue?

BeyondEvil commented 2 years ago

Have you looked at https://pytest-html.readthedocs.io/en/latest/user_guide.html#extra-content ?

MartykQ commented 2 years ago

The question I meant was not about how to insert the data, but rather how to get data from fixture to pytest_html_results_summary hook. As for now, I've managed to work around it with writing to file after cleaning up the session scoped fixture and reading the same file in pytest_html_results_summary hook