[TIP] Generating tests dynamically (was Re: Meta-test methods...)

Augie Fackler lists at durin42.com
Sat Apr 25 16:09:10 PDT 2009

(Robert/Titus, sorry about the double-send)
On Apr 24, 2009, at 1:23 PM, C. Titus Brown wrote:

> -> At least in unittest, you can do this just by generating whatever  
> tests
> -> you want in TestSuite.__iter__.
> ->
> -> countTestCases clearly can't do a lot there, but that is the only  
> method
> -> in the protocol that conflicts with generation.
> This may seem tangential but IMO is not: could someone document the
> !%#!$!# out of unittest, please?
> Reading through this
> 	http://docs.python.org/library/unittest.html
> doesn't give me any clue as to how to extend TestSuite to do this;  
> sure,
> I can read (and modify) the source code, but basing a test suite for
> multiple versions of Python on unittest internals stirkes me as a tad
> risky.

I ended up doing dynamic test generation for hgsubversion, and the  
resulting source file is here:

Summary: build up the __dict__ of the test case class by hand, then  
call type() explicitly when you're done. Ugly, but works in both Nose  
and unittest, which was my initial goal.

> With nose, I'm fairly sure that once given an API for generating tests
> in my test suite, that API will continue to work.  That's partly  
> because
> I know (roughly) where Jason Pellerin lives, and partly because the  
> is rather minimal and it can be implemented in multiple ways.  With
> unittest, I don't have a good sense for what guarantees there are,  
> other
> than that what is specified in the docs.  I consider everything else  
> to
> be internal & subject to change and resulting backwards  
> incompatibility.
> cheers,
> --titus
> -- 
> C. Titus Brown, ctb at msu.edu
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

More information about the testing-in-python mailing list