unittest and automatically firing off tests

John J. Lee jjl at pobox.com
Sat Jun 21 07:57:19 EDT 2003


Tom Plunket <tomas at fancy.org> writes:

[...snip use of unittest...]
> Things I don't like about this?  You bet.
> 
> 1) Why in the name of all that is holy does unittest.main() throw
>    regardless of tests passing?

I guess you mean 'raise', not 'throw'.  Does it?  I don't think it
does.


> 2) Why can't I readily pass a list of tests to unittest.main()? 
>    (I mean, besides the fact that it's not implemented; was this
>    a concious ommision?)

PyUnit works in terms of TestSuites.  Read the docs.

For one kludge to run tests from several test scripts, see test.py in

http://wwwsearch.sourceforge.net/ClientCookie/src/ClientCookie-0.4.2a.tar.gz

Doubtless I could have done it better if I'd used all of PyUnit's
features.


> 3) I feel like I should automatically batch up tests and fire
>    them off to unittest.run() or something similar.  Is this as
>    straight-forward and easy, and could I batch them all into one
>    mega-suite?  Are there any reasons why I wouldn't want to do
>    that?

I've always found

import unittest
unittest.main()

to work fine for most things -- it builds test suites automatically if
you use standard naming conventions, and has useful command line
arguments, so you can run a particular TestCase or a particular test
method on a TestCase from the command line.

If you have particular stuff in mind, the source code is designed
allow easy configuration using TestSuites, TestRunners, etc. -- take a
look at it.

If that's not enough, I know it's hard, but you'll just have to admit
that you need to read the docs ;-)


John




More information about the Python-list mailing list