[TIP] Unittest Changes
Michael Foord
fuzzyman at voidspace.org.uk
Mon Jul 21 06:47:22 PDT 2008
C. Titus Brown wrote:
> On Mon, Jul 21, 2008 at 02:35:58PM +0100, Michael Foord wrote:
> -> Jonathan Lange wrote:
> ->
> -> Right - although virtually every project I've worked on with unittest
> -> had ended up with an ad-hoc test collection mechanism, so I think the
> -> 'discover_tests' features I've discussed are prima-facie needed.
>
> How difficult (and controversial) do you think it would be to provide a
> "test hook" that could reside in some top-level place (setup.py, or
> module __init__, or something) that would let you override
> discover_tests with your own evil algorithm?
>
> For example, setuptools lets you specify
>
> test_suite = 'nose.collector'
>
> if you want to have
>
> python setup.py test
>
> run nose.
>
> It would be nice to have this a bit more programmatically available, so
> that you don't have to run setup.py. Or maybe it doesn't matter... what
> do you think?
>
>
Can you suggest how it might be implemented in unittest?
If it can be done *cleanly* then it shouldn't be too controversial.
If a module has this attribute:
test_suite = 'something.else'
Then how should unittest invoke 'something.else' ? (And must
'something.else' then present a suite compatible with a unittest
TestRunner ?)
Would it it look like this (with the __import__ call fixed of course - I
can *never* remember the args off the top of my head):
if hasattr(module, 'test_suite'):
collector = __import__(module.test_suite)
suite_from_module = collector(module)
else:
suite_from_module = unittest.collect_tests(module)
I'm not 100% convinced that this is the job of unittest, but if it can
be done cleanly in a way that is already compatible with nose then it
could be cool.
Michael
> cheers,
> --titus
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.resolverhacks.net/
http://www.theotherdelia.co.uk/
More information about the testing-in-python
mailing list