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

前端 未结 13 1342
野的像风
野的像风 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 22:47

    Following on from amatellanes' answer, if you're on Python3.4, you can't use _outcomeForDoCleanups. Here's what I managed to hack together:

    def _test_has_failed(self):
        for method, error in self._outcome.errors:
            if error:
                return True
        return False
    

    yucky, but it seems to work.

提交回复
热议问题