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

Is it possible to generate report at the end of each Pytest session

Open barnwal-paras opened this issue 5 years ago • 5 comments
trafficstars

In my Automation Suite, I am running multiple session, but single HTML report is getting generated which contains test report of all the session combined. Is there a way to generate report for each session individually ?

barnwal-paras avatar Jan 10 '20 11:01 barnwal-paras

@barnwal-paras When you say "multiple session", do you mean using xdist or multiple calls to pytest or something else?

BeyondEvil avatar Jan 13 '20 15:01 BeyondEvil

@BeyondEvil No, I am using a parametrised session scoped fixture and wanted to generate report at the end of every session, as a part of teardown of that fixture.

barnwal-paras avatar Jan 15 '20 11:01 barnwal-paras

@barnwal-paras Not sure I follow. Could you give an example in code?

Do you want a report for each session?

BeyondEvil avatar Jan 15 '20 12:01 BeyondEvil

@pytest.fixture(scope="session", params=[session1_config, session2_config])
def config(request, chrome_config):
    setup()
    yield 
    teardown()

I want report to be generated everytime teardown is called for those set of test having same parameter.

barnwal-paras avatar Jan 15 '20 12:01 barnwal-paras

Similar to #254, this would require a major refactor due to the fact that today, the entire report is done in memory until the pytest_sessionfinish hook is called - that's when the writing of the report to disk happens.

One option would be for you to import the HTMLReport class yourself, and add the logic necessary to generate a report for each session.

BeyondEvil avatar Jan 15 '20 21:01 BeyondEvil