unittest and automatically firing off tests

Tom Plunket tomas at fancy.org
Sat Jun 21 20:27:31 CEST 2003


John J. Lee wrote:

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

Yes, I mean raise, and yes, it does.  Have you tried executing it
before trying to give advice?

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

Yes I know.  Unfortunately, those of us who have read the docs
and read the code understand that unittest.main() takes a module
name or a module, and not a TestSuite.

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

Yeah, that's a pretty miserable hack.  From discussions
elsewhere, sucking in all of the tests in that way is pretty much
not nice.  ;)

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

Ok, but remember that that only works if all of your tests are in
the global namespace.  I suppose that can be, but that's not
really what I'm looking for either.


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

Thanks, maybe you should yourself before offering this advice.  I
have found that the docs that are available are seriously
incomplete so I ended up actually reading the code.


-tom!




More information about the Python-list mailing list