[TIP] suite, test_suite, load_tests ... Oh My ! WAS: unittest2 discovery / doctest integration?

Michael Foord fuzzyman at voidspace.org.uk
Wed May 5 05:01:06 PDT 2010

On 05/05/2010 12:53, Olemis Lang wrote:
> On Tue, May 4, 2010 at 9:27 PM, Robert Collins
> <robertc at robertcollins.net>  wrote:
>> Hi Olemis,
> :o)
> [...]
>> load_tests is something that was designed after we hit the
>> limits of test_suite in bzr. As such its not surprising that they can
>> do similar things - but load_tests has less duplication (it gets the
>> already found tests, and can decorate or replace as it desires).
> Is there any code snippet illustrating these limitations ? AFAIK&
> AFAICS I can do anything I want inside `test_suite` ...
How about reusing the same loader that is being used to load the module?

How about customising test discovery into a package?

Both trivially easy to do with load_tests - basically not possible with 
test_suite. Additionally taking the standard set of tests for the module 
and decorating / adding to it is trivially easy with load_tests (it is 
passed in) but requires more code with test_suite (which has to build it 

As an aside your previous email talked about the "existing convention" 
and then discussed *both* suite functions and *test_suite* functions. 
Basically there wasn't a single convention prior to the introduction of 
load_tests (and *definitely* none supported directly by the TestLoader).

On the other hand if you still want to use suite / test_suite (or 
anything else) then you can stay compatible with load_tests very easily. 
Although the code to do it is *hugely* complicated:

def load_tests(loader, tests, pattern):
return test_suite()

All the best,



READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.

More information about the testing-in-python mailing list