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

后端 未结 7 1896
一向
一向 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条回答
  • 2021-02-18 17:32

    I came access this question, trying to figure out internal data structure for the session instance.

    Iterating over session.items you can check rep_call.outcome for string representation of the test result.

    def pytest_sessionfinish(session, exitstatus):
        for item in session.items:
            print('{} {}'.format(item.name, item.rep_call.outcome))
    

    With trivial test cases you get this

    test_positive passed
    test_negative failed
    
    0 讨论(0)
提交回复
热议问题