parametized unittest

Ben Finney ben+python at benfinney.id.au
Sat Jan 11 23:22:47 EST 2014


CraftyTech <hmmedina at gmail.com> writes:

> I'm trying parametize my unittest so that I can re-use over and over,
> perhaps in a for loop.

The ‘testscenarios’ <URL:https://pypi.python.org/pypi/testscenarios>
library allows you to define a set of data scenarios on your
FooBarTestCase and have all the test case functions in that class run
for all the scenarios, as distinct test cases.

e.g. a class with 5 scenarios defined, and 3 test case functions, will
run as 15 distinct test cases with separate output in the report.

> The loop will break after the first failure. Anyone have a good
> approach for this? please advise.

Yes, this is exactly the problem addressed by ‘testscenarios’. Enjoy it!

-- 
 \            “Program testing can be a very effective way to show the |
  `\        presence of bugs, but is hopelessly inadequate for showing |
_o__)                              their absence.” —Edsger W. Dijkstra |
Ben Finney




More information about the Python-list mailing list