@@ -108,7 +108,7 @@ def test_target(target # type: Any
108108test_target .__test__ = False # disable this function in pytest (otherwise name starts with 'test' > it will appear)
109109
110110
111- def cases_generator (name_template , # type: str
111+ def cases_generator (names = None , # type: Union[ str, Callable[[Any], str], Iterable[str]]
112112 lru_cache = False , # type: bool
113113 ** param_ranges # type: Iterable[Any]
114114 ):
@@ -127,9 +127,11 @@ def cases_generator(name_template, # type: str
127127 >>> outs = i+1, i+2
128128 >>> return ins, outs, None
129129
130- :param name_template: a name template, that will be transformed into the case name using
131- `name_template.format(**params)` for each case, where params is the dictionary of parameter values for this
132- generated case.
130+ :param names: a name template, that will be transformed into the case name using
131+ `names.format(**params)` for each case, where `params` is the dictionary of parameter values for this
132+ generated case. Alternately a callable returning a string can be provided, in which case
133+ `names(**params)` will be used. Finally an explicit list of names can be provided, in which case it should have
134+ the correct length (an error will be raised otherwise).
133135 :param lru_cache: a boolean (default False) indicating if the generated cases should be cached. This is identical
134136 to decorating the function with an additional `@lru_cache(maxsize=n)` where n is the total number of generated
135137 cases.
@@ -141,7 +143,7 @@ def cases_generator(name_template, # type: str
141143
142144 def cases_generator_decorator (test_func ):
143145 kwarg_values = list (product (* param_ranges .values ()))
144- setattr (test_func , _GENERATOR_FIELD , (name_template , param_ranges .keys (), kwarg_values ))
146+ setattr (test_func , _GENERATOR_FIELD , (names , param_ranges .keys (), kwarg_values ))
145147 if lru_cache :
146148 nb_cases = len (kwarg_values )
147149 # decorate the function with the appropriate lru cache size
0 commit comments