File: example.rst

package info (click to toggle)
python-ddt 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 136 kB
  • ctags: 80
  • sloc: python: 225; makefile: 140; sh: 3
file content (49 lines) | stat: -rw-r--r-- 1,894 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Example usage
=============

DDT consists of a class decorator ``ddt`` (for your ``TestCase`` subclass)
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 file.

This allows you to write your tests as:

.. literalinclude:: ../test/test_example.py
   :language: python

Where ``test_data_dict.json``:

.. literalinclude:: ../test/test_data_dict.json
   :language: javascript

and ``test_data_list.json``:

.. literalinclude:: ../test/test_data_list.json
   :language: javascript

And then run them with::

    $ nosetests -v test/test_example.py
    test_10_greater_than_5 (test.test_example.FooTestCase) ... ok
    test_2_greater_than_1 (test.test_example.FooTestCase) ... ok
    test_file_data_dict_sorted_list (test.test_example.FooTestCase) ... ok
    test_file_data_dict_unsorted_list (test.test_example.FooTestCase) ... ok
    test_file_data_list_Goodbye (test.test_example.FooTestCase) ... ok
    test_file_data_list_Hello (test.test_example.FooTestCase) ... ok
    test_larger_than_two_12 (test.test_example.FooTestCase) ... ok
    test_larger_than_two_23 (test.test_example.FooTestCase) ... ok
    test_larger_than_two_3 (test.test_example.FooTestCase) ... ok
    test_larger_than_two_4 (test.test_example.FooTestCase) ... ok
    test_not_larger_than_two_-3 (test.test_example.FooTestCase) ... ok
    test_not_larger_than_two_0 (test.test_example.FooTestCase) ... ok
    test_not_larger_than_two_1 (test.test_example.FooTestCase) ... ok
    test_not_larger_than_two_2 (test.test_example.FooTestCase) ... ok
    test_undecorated (test.test_example.FooTestCase) ... ok

    ----------------------------------------------------------------------
    Ran 15 tests in 0.002s

    OK

6 test methods + some *magic* decorators = 15 test cases.