Skip to content

Parameterized tests

Yoshi van den Akker requested to merge parameterized-tests into master

Adds support for parameterized test cases:

    >>> @parameterized(spectest, [          # All test cases are a separate spectest
    ...     (0, 0),                         # No custom name, using default weight
    ...     ("foo", 1, 2),                  # Custom name, using default weight
    ...     (3, 2, 4),                      # Weight = 3
    ...     ("quad", 4, 3, 6)],             # Custom name, weight = 4
    ...     2)                              # Tests without custom weight use 2 as default
    ... def test_func(self, input, expected):
    ...     actual = func(input)
    ...     self.assertEqual(expected, actual)
    ...
    >>> locals()                            # List all tests:
    ... 'test_func_0': <function ...>       # Will be wrapped in ``spectest(2)``, weight is 2/11
    ... 'test_func_1_foo': <function ...>   # Will be wrapped in ``spectest(2)``, weight is 2/11
    ... 'test_func_2': <function ...>       # Will be wrapped in ``spectest(3)``, weight is 3/11
    ... 'test_func_3_quad': <function ...>  # Will be wrapped in ``spectest(4)``, weight is 4/11
Edited by Maarten Sijm

Merge request reports

Loading