[TIP] Using one unit test with different input parameters
Robert McHardy
robert at mchardy.net
Wed Feb 20 04:07:31 PST 2008
On 19 Feb 2008, at 22:18, Ben Finney wrote:
> Robert McHardy <robert at mchardy.net> writes:
>
>> The client has 28 sites that are very similar. I'd rather not have
>> to clone the test script 28 times with different hard-coded domain
>> details... but I can't figure out how to pass in different
>> parameters to the unit test - e.g. a different DOMAIN dict with data
>> for other sites, and have the tests run on that domain instead.
>
> I often use the test fixtures to store a container of test parameter
> sets, then iterate over those parameter sets inside the test cases::
>
> # ... etc ...
>
> In the test case given above, the 'sites' dict could simply be a
> module global instead, since it's not necessary to create it each
> time. If it contains anything that needs to be set up for each test
> case, keep it in the fixtures.
>
>> Any tips or hints gratefully received!
>
> You're using unittest.TestCase, but not using any of the
> 'failUnlessFoo' methods; that means the unittest reports won't be very
> informative about what fails.
>
Thanks to all for the hints - I'm going to try both extending the
unit tests with iteration over multiple sites (might be easiest), and
also Terry's suggestion of test generators in nose.
Cheers, Rob.
More information about the testing-in-python
mailing list