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

后端 未结 6 837
陌清茗
陌清茗 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:33

    If you want results of the tests you can use hook runtest_makereport:

    @pytest.hookimpl(tryfirst=True, hookwrapper=True)
    def pytest_runtest_makereport(item, call):
        outcome = yield
        rep = outcome.get_result()
        if rep.when == 'call' and rep.failed:
            mode = 'a' if os.path.exists('failures') else 'w'
            try:  # Just to not crash py.test reporting
              pass  # the test 'item' failed
            except Exception as e:
                pass
    

提交回复
热议问题