[TIP] Using one unit test with different input parameters

Jonathan Lange jml at mumak.net
Tue Feb 19 15:36:54 PST 2008


On Feb 20, 2008 10:31 AM, Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> Robert Collins <robertc at robertcollins.net> writes:
>
> > You might like to look at bzrlib.tests.TestScenarioApplier. In
> > combination with bzrlib.tests.TestUtil.TestLoader, which extends
> > unittests TestLoader, you can very easily parameterise some tests in
> > a test script while preserving others.
> >
> > For example, in the above example of sites, you might do:
> > --test_foo.py
> > ...
> > def load_tests(standard_tests, module, loader):
> >     """Multiply tests version and protocol consistency."""
> >     applier = TestScenarioApplier()
> >     applier.scenarios = [
> >       ('wessex', {'primary': 'wessexfm.com', 'code': 'wx'}),
> >         ('example.com', {'primary': 'example.com', 'code': 'ec'}),
> >         ('example.org', {'primary': 'example.org', 'code': 'eo'}),
> >         ]
> >     # adapt everything
> >     for test in iter_suite_tests(standard_tests):
> >         result.addTests(applier.adapt(test))
> >     return result
> >
> > class TestSite(TestCase):
> >     def test_a(self):
> >         pass
> >     def test_b(self):
> >         pass
> > ---
>
> Looks interesting. How does the above code work with the extended
> TestLoader <URL:http://www.python.org/doc/lib/testloader-objects.html>
> class?
>

You have to use the bzrlib TestLoader, which inherits from the
standard library's TestLoader.

Also, I'm not sure exactly what you mean by "extended" here.

jml



More information about the testing-in-python mailing list