|
Project Information
Featured
Downloads
|
Introductionparameterized-testcase works with Python's standard unittest module to provide a means to run TestCases with different "parameterizations". Parameterizations mean any members of the TestCase class which influence the tests or the environment in which they run. UsageFor example, here's how you might parameterize a TestCase on the database backend it uses. Each TestCase subclass created by parameterize() has a class-level member named "backend" which the class can use to determine which backend to use: from parameterized_testcase import parameterize
import my_module
# Define your "testcase" without subclassing from `unittest.TestCase`.
class MyTest:
def setUp(self):
# Here's where the class uses the parameters provided by
# `parameterize()`.
self.connection = my_module.open(
type(self).backend)
def test_something(self):
self.assertTrue(...)
# Each key in `params` is a name of a parameterization. Each value in
# `params` is a dict defining attributes to add to the generated
# `TestCase` subclasses. In this case, each generated subclass will
# have an attribute named "backend".
params = {
'sqlite': { 'backend': 'sqlite' }
'postgres': { 'backend': 'postgres' },
}
# This actually generates the `unittest.TestCase` subclasses. The
# generated classes will be named "MyTest_<param-name>" where
# `<param-name>` comes from the keys in the params argument.
cases = parameterize(cases=[MyTest],
params=params))InstallationInstallation instruction are on the wiki. DocumentationThe primary documentation is here. FeedbackWe'd love to hear your feedback, positive or negative. Does parameterized-testcase work for you? How are you using it? What's missing? Let us know! |