default test method name in unittest framework

Vyacheslav Maslov slava.maslov at gmail.com
Mon May 7 03:49:12 EDT 2007


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

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?

2007/5/7, Gabriel Genellina <gagsl-py2 at yahoo.com.ar>:
>
> En Sun, 06 May 2007 22:17:44 -0300, Vyacheslav Maslov
> <slava.maslov at gmail.com> escribió:
>
> > i have question related to python's unit testing framework.
> >
> > Take a look at unittest.TestCase class. The main method which contains
> > all
> > code related to test case execution have name "run". But in the same
> time
> > constructor of unittest.TestCase class have param methodName with
> default
> > value "runTest", not "run"! Why? This leads to AttributeError exception
> > if i
> > do not explicitly set methodName to "run" during TestCase
> initialization.
>
> No: method run is used by the framework, it internally calls the setUp,
> tearDown, etc. You don't have to override run (you must not override
> run!), instead, you provide the runTest method in your class.
> Furthermore, instead of many similar TestCase classes, you can write a
> single class with many methods named testXXX, and they will be found and
> used by a TestLoader.
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070507/3be63c3a/attachment.html>


More information about the Python-list mailing list