[TIP] Generating tests dynamically (was Re: Meta-test methods...)
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
> -> you want in TestSuite.__iter__.
> -> countTestCases clearly can't do a lot there, but that is the only
> -> 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
> doesn't give me any clue as to how to extend TestSuite to do this;
> 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
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
> 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,
> than that what is specified in the docs. I consider everything else
> be internal & subject to change and resulting backwards
> C. Titus Brown, ctb at msu.edu
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
More information about the testing-in-python