Add additional parameterization to a test function. This function create or adds to the `_parameterize` property of a function which is then expanded by the RunnerMeta metaclass into multiple separate test functions.
(func, parameters)
| 630 | |
| 631 | |
| 632 | def parameterize(func, parameters): |
| 633 | """Add additional parameterization to a test function. |
| 634 | |
| 635 | This function create or adds to the `_parameterize` property of a function |
| 636 | which is then expanded by the RunnerMeta metaclass into multiple separate |
| 637 | test functions. |
| 638 | """ |
| 639 | prev = getattr(func, '_parameterize', None) |
| 640 | assert not any(p.startswith('_') for p in parameters), 'test variant names should not start with _' |
| 641 | if prev: |
| 642 | # If we're parameterizing 2nd time, construct a cartesian product for various combinations. |
| 643 | func._parameterize = { |
| 644 | '_'.join(filter(None, [k1, k2])): v2 + v1 for (k1, v1), (k2, v2) in itertools.product(prev.items(), parameters.items()) |
| 645 | } |
| 646 | else: |
| 647 | func._parameterize = parameters |
| 648 | |
| 649 | |
| 650 | def parameterized(parameters): |