default test method name in unittest framework
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon May 7 04:14:29 EDT 2007
En Mon, 07 May 2007 04:49:12 -0300, Vyacheslav Maslov
<slava.maslov at gmail.com> escribió:
> Yes, i general you are right. I meant following case, please look at my
> example
>
> Suppose i have following simple test case:
>
> import unittest
>
> class SomeTest(unittest.TestCase):
>
> def testAdd(self):
> self.assertEqual(2+2,4)
>
> if __name__=="__main__":
> unittest.TextTestRunner().run(SomeTest())
>
> this code produce following exception:
> ValueError: no such test method in <class '__main__.SomeTest'>: runTest
>
> Because default test method name is "run", but TestCase class have
> constructor parameter testMethod with default value "runTest" not "run"!
NO! the default test method name is not "run" but "runTest", as explained
in my previous post. You can either rename the testAdd method to runTest,
or change the last line to be, simply:
if __name__=="__main__":
unittest.main()
main() will create a TestRunner, a TestLoader, a TestSuite containing all
your TestCases, and run them.
> As result i always should explicitly pass testMethod name when create
> object
> of test case class:
> unittest.TextTestRunner().run(SomeTest("run"))
>
> Why i should do this?
You should *not* do that! Your tests will not even be run that way.
--
Gabriel Genellina
More information about the Python-list
mailing list