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

后端 未结 6 842
陌清茗
陌清茗 2021-02-18 17:03

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

6条回答
  •  甜味超标
    2021-02-18 17:35

    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.

提交回复
热议问题