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

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

    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]

提交回复
热议问题