pytest: How to get a list of all failed tests at the end of the session? (and while using xdist)

后端 未结 7 2066
一向
一向 2021-02-18 16:46

I would like to have a list of all the tests that have failed to be used at the end of session.

Pytest lets you define a hook pyt

7条回答
  •  旧时难觅i
    2021-02-18 17:18

    I wanted a concise report of failed tests and parametrized variations so went with pytest_terminal_summary in conftest.py:

    def pytest_terminal_summary(terminalreporter, exitstatus, config):
        terminalreporter.section('Failed tests')
        failures = [report.nodeid.split('::')[-1]
                    for report in terminalreporter.stats.get('failed', [])]
        terminalreporter.write('\n'.join(failures) + '\n')
    

    If you inspect terminalreporter._session.items, there's more information you can add to the report, this is just what I wanted.

提交回复
热议问题