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

Generate partial HTML report on abort

Open acohen716 opened this issue 3 years ago • 3 comments

We are running into a situation with the combination of pytest-repeat and pytest-html where we repeat a test n times yet if aborted (for example by Jenkins) no HTML report is generated. This occurs even if n - 1 iterations ran successfully and pytest execution was only aborted during the last iteration. I welcome any suggestions/solutions that I can implement myself (for example in conftest.py).

acohen716 avatar Mar 16 '22 09:03 acohen716

This is going to be solved by next-gen, as the report is updated per test.

BeyondEvil avatar Mar 20 '22 15:03 BeyondEvil

Great, thanks @BeyondEvil!

2 follow-up questions:

  1. Is there a target date for next-gen?
  2. In the meantime as a temporary solution would there be any downsides to doing something like this (code snippet quoted below)?
@pytest.fixture(scope='function', autouse=True)
def test_blackbox(request):
    session = request.node
    html = request.config._html
    report_content = html._generate_report(session)
    html._save_report(report_content)

acohen716 avatar Mar 30 '22 19:03 acohen716

Great, thanks @BeyondEvil!

2 follow-up questions:

  1. Is there a target date for next-gen?
  2. In the meantime as a temporary solution would there be any downsides to doing something like this (code snippet quoted below)?
@pytest.fixture(scope='function', autouse=True)
def test_blackbox(request):
    session = request.node
    html = request.config._html
    report_content = html._generate_report(session)
    html._save_report(report_content)

No target-date, sorry.

I'm sure there are downsides, the question is how relevant they are.

For one, this isn't being called: https://github.com/pytest-dev/pytest-html/blob/360f1204678e1e837cb2bcc8e27f7adb5db6a2e0/src/pytest_html/html_report.py#L270

You may also get issue when trying to overwrite an existing report.

BeyondEvil avatar Mar 31 '22 00:03 BeyondEvil