[TIP] Test Parameterization with unittest
Michael Foord
fuzzyman at voidspace.org.uk
Mon May 11 09:33:27 PDT 2009
Ben Finney wrote:
> Michael Foord <fuzzyman at voidspace.org.uk> writes:
>
>
>> class Test(TestCaseWithParams):
>> params = [(1, 1), (2, 3), (2, 2), (3, 5)]
>>
>> def assertWithParams(self, a, b):
>> self.assertEqual(a, b)
>>
>
> I prefer the API for the ‘testscenarios’ library
> <URL:https://launchpad.net/testscenarios>, where each scenario has a
> name and an arbitrary dict of the scenario parameters
> <URL:http://bazaar.launchpad.net/~lifeless/testscenarios/trunk/annotate/head%3A/README>.
>
> scenarios = [
> ('foo', {'spam': True, 'eggs': 17, 'beans': [0, 1]}),
> ('bar', {'spam': False, 'eggs': 23, 'beans': [1, 1, 0]}),
> ]
>
>
Yeah - that's a nicer API for having multiple scenarios in a single test
class. I'll read about it and propose something for unittest.
Currently trying to write tests for test discovery.
Michael
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
More information about the testing-in-python
mailing list