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

后端 未结 7 1911
一向
一向 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:14

    You can use command line option --result-log:

    test_dummy.py:

    def test_dummy_success():
        return
    
    
    def test_dummy_fail():
        raise Exception('Dummy fail')
    

    Command line:

    $ py.test --result-log=test_result.txt
    

    Content of the test_result.txt

    . test_dummy.py::test_dummy_success
    F test_dummy.py::test_dummy_fail
     def test_dummy_fail():
     >       raise Exception('Dummy fail')
     E       Exception: Dummy fail
    
     test_dummy.py:6: Exception
    

    Just search 'F' in first column and after that would be [file]::[test]

提交回复
热议问题