unittest can not use function name 'test' ?

Fredrik Lundh fredrik at pythonware.com
Mon Nov 21 11:37:22 CET 2005


ajikoe at gmail.com wrote:

> 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>






More information about the Python-list mailing list