unittest can not use function name 'test' ?

A

ajikoe

Hello

I found something strange in my unittest :
This code is ok (will report error ):

class MyTest1(unittest.TestCase):

def runTest(self):
self.assertEqual(2,3)
pass

if __name__ == '__main__':
unittest.main()


But if I add a function with the first name is 'test' it fails to
recognize the error:
class MyTest1(unittest.TestCase):
def test1(self):
pass

def runTest(self):
self.assertEqual(2,3)
pass

if __name__ == '__main__':
unittest.main()


Please help
pujo
 
F

Fredrik Lundh

I found something strange in my unittest :
This code is ok (will report error ):

class MyTest1(unittest.TestCase):

def runTest(self):
self.assertEqual(2,3)
pass

if __name__ == '__main__':
unittest.main()

But if I add a function with the first name is 'test' it fails to
recognize the error:

class MyTest1(unittest.TestCase):
def test1(self):
pass

def runTest(self):
self.assertEqual(2,3)
pass

if __name__ == '__main__':
unittest.main()

the runTest() method is a fallback, and is only used if you don't have any
test*() methods in your test case. see e.g.

http://docs.python.org/lib/organizing-tests.html

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top