[TIP] unittest2/nose2: plugin interaction or overrides or ... ?

jason pellerin jpellerin at gmail.com
Tue Aug 31 06:48:43 PDT 2010


On Sun, Aug 29, 2010 at 4:03 PM, Michael Foord
<fuzzyman at voidspace.org.uk> wrote:
>  On 26/08/2010 16:29, jason pellerin wrote:
>>
>> Next up on my nose2 compatibility checklist is squeezing nose's
>> support for implicit generator tests and for more names for test
>> functions' fixtures (setup and teardown in addition to setUp and
>> tearDown for instance) into nose2. unittest2's moduleloading plugin is
>> about 90% there, but I think it will be important for nose2 uptake to
>> avoid making people rename 1,000 setup functions and/or tag 1,000
>> generator tests manually in pre-existing test suites. So I'm trying to
>> figure out what is the best way to interact with moduleloading from
>> another plugin.
>>
>> Right now I can see 2 solutions: I can force my plugin to run first so
>> that it has a chance to load test objects and change or add the
>> attributes that moduleloading is looking for. Or I can subclass some
>> of the moduleloading plugins, force moduleloading not to load, and
>> load my plugin instead.
>
> Hmm... in this case I don't want to add multiple ways to do this to support
> backwards compatibility with nose. I think the easiest way to do this is to
> add moduleloading to 'excludedplugins' in the nose2 config file and provide
> your own functionality instead.

Ok, I can go along with that.

> Let me know if I can change anything in moduleloading (I don't like the name
> and may change it - suggestions welcomed) to make it more reusable.

A couple of things would help:

- break out the check for generatorness and the extraction of setup
and teardown attributes into methods I can override. (eg isGenerator =
self.isGenerator(obj) instead of isGenerator = getattr(obj,
'testGenerator', False)
- in testsFromGenerator, either make testsFromGeneator a method itself
and have it call an overridable method instead of enumerate() for
iterating the generator, or allow testsFromGenerator to take a
callback that is called instead of enumerate.

The reason for the latter change is that nose expects generator tests'
yields to look like this:

yield callable_or_name, arg, arg, arg

and I'd like to support that as well as unittest2's:

yield callable, (arg, arg, arg)

to do that cleanly, this line:

for index, (func, args) in enumerate(generator):

needs to change (or nose needs to wrap each generator func it sees in
another generator that munges the output, but I think that would mess
up user's tracebacks so I'd rather avoid it if possible).

Thanks,

JP



More information about the testing-in-python mailing list