[TIP] Test discovery for unittest
Michael Foord
fuzzyman at voidspace.org.uk
Sat Apr 4 16:38:15 PDT 2009
Robert Collins wrote:
> 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 :).
>
>
Right - nice. It also lets it be used with a custom test runner.
> 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.
>
Right. I wonder if importlib makes this any easier?
> 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.
>
>
You mean that if a package explicitly loads tests from a subpackage into
its namespace?
We could keep track of test classes loaded and drop duplicates.
I've been given the go ahead to apply your patch for __iter__ by the way.
I've modified my recipe to include the DiscoveringTestSuite - need to
think about a testing strategy.
> I'm not sure of the right answer to that yet :).
>
Ignore the problem initially. :-)
Michael
> -Rob
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
More information about the testing-in-python
mailing list