r"""Deliver multiple versions of a test based on positional combinations. This is a facade over pytest.mark.parametrize. :param \*comb: argument combinations. These are tuples that will be passed positionally to the decorated function. :param argnames: optional list of argument
(
*comb: Union[Any, Tuple[Any, ...]],
argnames: Optional[str] = None,
id_: Optional[str] = None,
**kw: str,
)
| 88 | |
| 89 | |
| 90 | def combinations( |
| 91 | *comb: Union[Any, Tuple[Any, ...]], |
| 92 | argnames: Optional[str] = None, |
| 93 | id_: Optional[str] = None, |
| 94 | **kw: str, |
| 95 | ) -> Callable[[_FN], _FN]: |
| 96 | r"""Deliver multiple versions of a test based on positional combinations. |
| 97 | |
| 98 | This is a facade over pytest.mark.parametrize. |
| 99 | |
| 100 | |
| 101 | :param \*comb: argument combinations. These are tuples that will be passed |
| 102 | positionally to the decorated function. |
| 103 | |
| 104 | :param argnames: optional list of argument names. These are the names |
| 105 | of the arguments in the test function that correspond to the entries |
| 106 | in each argument tuple. pytest.mark.parametrize requires this, however |
| 107 | the combinations function will derive it automatically if not present |
| 108 | by using ``inspect.getfullargspec(fn).args[1:]``. Note this assumes the |
| 109 | first argument is "self" which is discarded. |
| 110 | |
| 111 | :param id\_: optional id template. This is a string template that |
| 112 | describes how the "id" for each parameter set should be defined, if any. |
| 113 | The number of characters in the template should match the number of |
| 114 | entries in each argument tuple. Each character describes how the |
| 115 | corresponding entry in the argument tuple should be handled, as far as |
| 116 | whether or not it is included in the arguments passed to the function, as |
| 117 | well as if it is included in the tokens used to create the id of the |
| 118 | parameter set. |
| 119 | |
| 120 | If omitted, the argument combinations are passed to parametrize as is. If |
| 121 | passed, each argument combination is turned into a pytest.param() object, |
| 122 | mapping the elements of the argument tuple to produce an id based on a |
| 123 | character value in the same position within the string template using the |
| 124 | following scheme: |
| 125 | |
| 126 | .. sourcecode:: text |
| 127 | |
| 128 | i - the given argument is a string that is part of the id only, don't |
| 129 | pass it as an argument |
| 130 | |
| 131 | n - the given argument should be passed and it should be added to the |
| 132 | id by calling the .__name__ attribute |
| 133 | |
| 134 | r - the given argument should be passed and it should be added to the |
| 135 | id by calling repr() |
| 136 | |
| 137 | s - the given argument should be passed and it should be added to the |
| 138 | id by calling str() |
| 139 | |
| 140 | a - (argument) the given argument should be passed and it should not |
| 141 | be used to generated the id |
| 142 | |
| 143 | e.g.:: |
| 144 | |
| 145 | @testing.combinations( |
| 146 | (operator.eq, "eq"), |
| 147 | (operator.ne, "ne"), |