开发者

A way to output pyunit test name in setup()

开发者 https://www.devze.com 2023-01-31 12:14 出处:网络
Is there a way in python for a pyunit test to outp开发者_StackOverflow中文版ut the test it\'s currently running.Example:

Is there a way in python for a pyunit test to outp开发者_StackOverflow中文版ut the test it's currently running. Example:

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

def test_example(self):
    #do stuff

def test_example2(self):
    #do other stuff

def tearDown(self):
    log.debug("Test %s Finished" % (testname))


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

def setUp():
    print("In method", self._testMethodName)


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消