default test method name in unittest framework

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon May 7 02:48:18 EDT 2007


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




More information about the Python-list mailing list