### Navigation

- index
- modules |
- previous |
- DDT 0.4.0 documentation »

# API

`ddt.``data`(*values)

  Method decorator to add to your test methods.

  Should be added to methods of instances of `unittest.TestCase`.

`ddt.``ddt`(cls)

  Class decorator for subclasses of `unittest.TestCase`.

  Apply this decorator to the test case class, and then decorate test methods with `@data`.

  For each method decorated with `@data`, this will effectively create as many methods as data items are passed as parameters to `@data`.

  The names of the test methods follow the pattern `test_func_name + "_" + str(data)`. If `data.__name__` exists, it is used instead for the test method name.

  For each method decorated with `@file_data('test_data.json')`, the decorator will try to load the test_data.json file located relative to the python file containing the method that is decorated. It will, for each `test_name` key create as many methods in the list of values from the `data` key.

  The names of these test methods follow the pattern of `test_name` + str(data)``

`ddt.``file_data`(value)

  Method decorator to add to your test methods.

  Should be added to methods of instances of `unittest.TestCase`.

  `value` should be a path relative to the directory of the file containing the decorated `unittest.TestCase`. The file should contain JSON encoded data, that can either be a list or a dict.

  In case of a list, each value in the list will correspond to one test case, and the value will be concatenated to the test method name.

  In case of a dict, keys will be used as suffixes to the name of the test case, and values will be fed as test data.

### Navigation

- index
- modules |
- previous |
- DDT 0.4.0 documentation »