首页 > 解决方案 > Is it possible to generate a pytest HTML report on a timeout?

问题描述

I'm using pytest and want to combine two plugins in a graceful way, pytest-html and pytest-timeout. I'm operating on Windows, so I have to use the thread-method of timing out from pytest-timeout, which causes a full-stop to all testing. I want an html from pytest-html to be generated in this instance, but was unsure of the plausibility of this from hierarchy issues with the interrupt.

UPDATE, progress so far: I've added a function to conftest.py that manually generates the html before every test case, with the session data that exists at that point. This is a roundabout method of generating the html before the timeout, as opposed to only at the end of testing, simply because the html is being continuously regenerated throughout the process.

@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)

I could add similar code to the timeout_timer method of timeout, which is the function that is called when the timer thread runs out, but I want to avoid directly editing the plugin itself. I'll answer once I complete my original task.

标签: pythonpytestpytest-html

解决方案


推荐阅读