[TIP] subclassing TestSuite to override __iter__ is painful

Olemis Lang olemis at gmail.com
Tue Apr 7 05:02:30 PDT 2009


On Mon, Apr 6, 2009 at 4:38 PM, Robert Collins
<robertc at robertcollins.net> wrote:
> On Mon, 2009-04-06 at 08:48 -0500, Olemis Lang wrote:
>> On Sat, Apr 4, 2009 at 5:03 PM, Robert Collins
>> <robertc at robertcollins.net> wrote:
>> > I've put a patch up here http://bugs.python.org/issue5693. In short, a
>> > TestSuite whose __iter__ does something more complex (such as test
>> > discover) requires you to reimplement nearly everything rather than just
>> > __iter__ and addTest. This makes it a lot simpler.
>> >
>>
>> Didnt see the patch but AFAIK ... test suites are there only to group
>> test cases ... not to perform test discovery (that's loaders business
>> ...)
>
> TestSuite/TestCase are a Composite in the GoF pattern language;

Yes

> as such
> TestSuite can do a lot more than group tests (and in fact grouping is
> almost entirely useless).
> TestSuite is delegated to when you run tests,
> and can safely do things like randomising order, managing common
> resources and more.
>

Yes I know. If you take a look at dutest.DocTestSuite class [1]_
you'll find out that's a class implemented to group instances of
DocTestCase, and also that it overrides its run method so as to invoke
doctest.DoctestRunner (wrapped by _Doc2UnittestRunner ;) in order to
verify the doctests retrieved by DocTestLoader. It also does some
other things, so, in general, I understand perfectly & have experience
implementing such kind of complex TestSuites ;) But all this is
related to grouping test cases, and running the test, not test
discovery.

>> This is IMHO ... ;)
>
> The patch that you haven't seen makes it simpler to write a subclass,
> thats all.
>

Ok but, as I already said, my comment was about TestSuites performing
test discovery ( that's indeed one of the examples you mentioned ).
That's what test loaders are there for ;o).

However I better take a look at the patch ... later ;)

.. [1] dutest.DocTestSuite
         (https://apps.sourceforge.net/trac/flioops/browser/py/trunk/utils/dutest.py?rev=91&marks=269-296#L268)

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:
Se retira el BDFL ... ¿El fin de Python 3k?



More information about the testing-in-python mailing list