Модульное тестирование Python: автоматический запуск отладчика в случае сбоя теста

Есть ли способ автоматически запустить отладчик в момент, когда unittest завершился ошибкой?

Сейчас я просто использую pdb.set_trace () вручную, но это очень утомительно, так как мне нужно добавлять его каждый раз и выньте его в конце.

Например:

import unittest

class tests(unittest.TestCase):

    def setUp(self):
        pass

    def test_trigger_pdb(self):
        #this is the way I do it now
        try:
            assert 1==0
        except AssertionError:
            import pdb
            pdb.set_trace()

    def test_no_trigger(self):
        #this is the way I would like to do it:
        a=1
        b=2
        assert a==b
        #magically, pdb would start here
        #so that I could inspect the values of a and b

if __name__=='__main__':
    #In the documentation the unittest.TestCase has a debug() method
    #but I don't understand how to use it
    #A=tests()
    #A.debug(A)

    unittest.main()
39
задан Martijn Pieters 30 March 2015 в 10:57
поделиться