[TIP] Test Parameterization with unittest
Ben Finney
ben+python at benfinney.id.au
Sun May 10 17:26:21 PDT 2009
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]}),
]
--
\ “Some people, when confronted with a problem, think ‘I know, |
`\ I'll use regular expressions’. Now they have two problems.” |
_o__) —Jamie Zawinski, in alt.religion.emacs |
Ben Finney
More information about the testing-in-python
mailing list