[TIP] dynamically create tests with unittest

Ben Finney ben+python at benfinney.id.au
Thu Feb 26 13:30:12 PST 2015

Albert-Jan Roskam <fomcl at yahoo.com> writes:

> I would have expected to have something like (pseudo code):
> for desired_value, actual_value, label in zip(desired_record, actual_record, labels):
>      generate_test(desired_value, actual_value, label)

The test case functionality also needs to be written, of course. At some
point you need to get concrete about what to do in the system under
test, and what assertion you want to make :-)

    def test_some_specific_condition(parameter_foo, parameter_bar):

Once you have functions written that do the tests given a set of
parameters, you can then parameterise those test functions to generate
test cases.


 \       “Homer, where are your clothes?” “Uh... dunno.” “You mean Mom |
  `\        dresses you every day?!” “I guess; or one of her friends.” |
_o__)                                    —Lisa & Homer, _The Simpsons_ |
Ben Finney

More information about the testing-in-python mailing list