[TIP] Using one unit test with different input parameters

Robert Collins robertc at robertcollins.net
Tue Feb 19 16:17:46 PST 2008


On Wed, 2008-02-20 at 11:12 +1100, Ben Finney wrote:
> [Robert and Johnathon, please don't send me copies of messages also
> sent to the list. Follow-up just to the list is fine.]
> 
> "Jonathan Lange" <jml at mumak.net> writes:
> 
> > On Feb 20, 2008 10:31 AM, Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> > > Robert Collins <robertc at robertcollins.net> writes:
> > >
> > > > You might like to look at bzrlib.tests.TestScenarioApplier. In
> > > > combination with bzrlib.tests.TestUtil.TestLoader, which extends
> > > > unittests TestLoader, you can very easily parameterise some
> > > > tests in a test script while preserving others.
> > >
> > > Looks interesting. How does the above code work with the extended
> > > TestLoader
> > > <URL:http://www.python.org/doc/lib/testloader-objects.html> class?
> > 
> > You have to use the bzrlib TestLoader, which inherits from the
> > standard library's TestLoader.
> > 
> > Also, I'm not sure exactly what you mean by "extended" here.
> 
> I'm using the term Robert Collins used above; he says the bzrlib
> TestLoader "extends unittest's TestLoader".

right; its a subclass of the stock test loader. One of the changes is
that when loading tests from a module it will call into the load_tests
attribute of that module to allow per-module customisation.

> My question was asking how the example code Robert gave relates to a
> TestLoader. All I see in his example is a 'load_tests' function; is
> that supposed to be defined on a class that I write in my unit test
> suite? Am I supposed to extend bzrlib's TestLoader?

load_tests is intended to be defined at module scope in the module that
is being loaded - as the example module I sketched did.

> If there's documentation online for this, please feel free to point me
> to that.

pydoc bzrlib.tests.TestUtil.TestLoader
then press / and type load_tests.

Or on the web:
http://starship.python.net/crew/mwh/bzrlibapi/bzrlib.tests.TestUtil.TestLoader.html

-Rob
-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.idyll.org/pipermail/testing-in-python/attachments/20080220/72b6b553/attachment-0001.pgp 


More information about the testing-in-python mailing list