DDT consists of a class decorator
ddt (for your
and two method decorators (for your tests that want to be multiplied):
data: contains as many arguments as values you want to feed to the test.
file_data: will load test data from a JSON or YAML file.
Only files ending with ".yml" and ".yaml" are loaded as YAML files. All other files are loaded as JSON files.
Normally each value within
data will be passed as a single argument to
your test method. If these values are e.g. tuples, you will have to unpack them
inside your test. Alternatively, you can use an additional decorator,
unpack, that will automatically unpack tuples and lists into multiple
arguments, and dictionaries into multiple keyword arguments. See examples
This allows you to write your tests as:
And then run them with your favourite test runner, e.g. if you use nose:
$ nosetests -v test/test_example.py
The number of test cases actually run and reported separately has been multiplied.
DDT will try to give the new test cases meaningful names by converting the data values to valid python identifiers.
Python 2.7.3 introduced hash randomization which is by default enabled on Python 3.3 and later. DDT's default mechanism to generate meaningful test names will not use the test data value as part of the name for complex types if hash randomization is enabled.
You can disable hash randomization by setting the
PYTHONHASHSEED environment variable to a fixed value before
running tests (
export PYTHONHASHSEED=1 for example).