Getting Python's unittest results in a tearDown() method

前端 未结 13 1334
野的像风
野的像风 2020-11-28 22:40

Is it possible to get the results of a test (i.e. whether all assertions have passed) in a tearDown() method? I\'m running Selenium scripts, and I\'d like to do some reporti

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 23:02

    In few words, this gives True if all test run so far exited with no errors or failures:

    class WatheverTestCase(TestCase):
    
        def tear_down(self):
            return not self._outcome.result.errors and not self._outcome.result.failures
    

    Explore _outcome's properties to access more detailed possibilities.

提交回复
热议问题