A way to output pyunit test name in setup()

前端 未结 3 1819

Is there a way in python for a pyunit test to output the test it\'s currently running. Example:

def setUp(self):
    log.debug(\"Test %s Started\" % (testna         


        
相关标签:
3条回答
  • 2020-12-09 01:29
    self.id().split('.')[-1]
    

    You can find the Documentation at: http://docs.python.org/library/unittest.html#unittest.TestCase.id

    edit: For 2.7 users, https://docs.python.org/2.7/library/unittest.html#unittest.TestCase.id

    0 讨论(0)
  • 2020-12-09 01:33

    You can usestr(self.id()).split()[4]. It could be found here http://docs.python.org/library/unittest.html#unittest.TestCase.id

    0 讨论(0)
  • 2020-12-09 01:48

    You can use self._testMethodName. This is inherited from the unittest.TestCase parent class.

    def setUp():
        print "In method", self._testMethodName
    
    0 讨论(0)
提交回复
热议问题