[TIP] Test discovery for unittest
fuzzyman at voidspace.org.uk
Fri Apr 10 14:19:48 PDT 2009
Marius Gedminas wrote:
> On Tue, Apr 07, 2009 at 06:04:42PM +0100, Michael Foord wrote:
>> Marius Gedminas wrote:
>>> I don't think I can give this discussion the full attention it deserves,
>>> but I'll at least outline the conventions that the Zope 3 world uses for
>>> Is this compatible with what you're discussing? I'm kind of wondering
>>> about the talk about controlling recursion.
>> It sounds *similar*, except:
>> - Test modules can be discovered from the file system by a loader /
>> custom suite
>> - Tests are loaded in the normal unittest way - by finding all TestCase
>> subclasses in each module found
> Zope 3 has some abstract base classes that subclass unittest.TestCase.
> I believe that's the reason for listing the ones you want explicitly
> instead of using unittest's autodiscovery.
The point of discovery is to avoid having to list things explicitly, you
don't have to use it.
If you look at the prototype you'll see that it skips classes that don't
have any tests on them. If your base classes don't have any tests it
wouldn't be a problem, if they do (why?) then you can use load_tests to
>> - Individual modules can optionally define 'load_tests' in which case
>> that is called to get the suite from the module
> And the presence of load_tests inhibits the automatic discovery of
> TestCase subclasses?
If load_tests exists then it is used to collect tests for the module and
inhibits *all* automatic discovery for the module (or package).
>> - If a package (in the __init__.py) defines 'load_tests' then that is
>> used to load the suite for the whole package and discovery does not
>> continue into the package directory (this is the 'controlling recursion'
>> I disagree that failing to load modules should not be a fatal error by
>> default. If a test system wants that behavior it can implement it itself
>> in load_tests.
> Your views are interesting ;)
They certainly are.
> Marius Gedminas
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
More information about the testing-in-python