Question

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" % (testname))

def test_example(self):
    #do stuff

def test_example2(self):
    #do other stuff

def tearDown(self):
    log.debug("Test %s Finished" % (testname))
Was it helpful?

Solution

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

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top