[TIP] Test discovery for unittest

Robert Collins robertc at robertcollins.net
Sat Apr 4 16:28:08 PDT 2009


On Sat, 2009-04-04 at 23:40 +0100, Michael Foord wrote:
> Robert Collins wrote:
> > On Sat, 2009-04-04 at 04:02 +0100, Michael Foord wrote:
> >
> >   
> >> Thanks - I should look at using a test loader rather than importing the 
> >> modules and pulling out the test cases myself.
> >>     
> >
> > Done, attached.
> >
> > -Rob
> >   
> Ha - good timing. I'd *just* committed a change to use the test loader - 
> basically using the same technique as you without the DiscoveringTestSuite.
> 
> http://code.google.com/p/unittest-ext/source/browse/trunk/discovery.py
> 
> Would be interested in which approach people prefer and what else should 
> be done before putting into unittest (integrating with unittest -m 
> command line args is the most important thing IMO).

DiscoveringTestSuite is just nice glue to let this mix in with other
test suites - discover some, specify others :).

There really should be totally separate introspection facilities for
finding python modules and packages. bzr's plugin support would be a lot
simpler if we didn't have to look for python files, exclude .pyc in -O
mode, exclude .pyo in normal mode etc etc. And the same support logic
would be most of the discovery logic.

There is only potential glitch with discovery, and thats packages.

Say you discover the tests in foo and foo.bar. If foo defines a test
loading hook (like test_suite or load_tests) which explicitly loads the
tests from foo.bar, then discovery will find bar's tests twice.

I'm not sure of the right answer to that yet :).

-Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.idyll.org/pipermail/testing-in-python/attachments/20090405/40249454/attachment.pgp 


More information about the testing-in-python mailing list