wolever / parameterized

Parameterized testing with any Python test framework
Other
833 stars 105 forks source link

@parameterized.expand fails with type hinting #126

Open tomepel opened 3 years ago

tomepel commented 3 years ago

@parameterized.expand is not compatible with type hinting.

Minimal working example (python 3.8, unittest)

def foo_bar_provider() -> List[List]:
    return [['foo'], ['bar']]

  @parameterized.expand(foo_bar_provider)
    def test_foo_bar(self, provider: str):

Gives the following error

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File <LOCAL>
  File <LOCAL>
    def test_foo_bar(self, provider: str):
  File "/usr/local/lib/python3.8/dist-packages/parameterized/parameterized.py", line 383, in parameterized_expand_wrapper
    frame_locals[name].__doc__ = doc_func(f, num, p)
  File "/usr/local/lib/python3.8/dist-packages/parameterized/parameterized.py", line 189, in default_doc_func
    all_args_with_values = parameterized_argument_value_pairs(func, p)
  File "/usr/local/lib/python3.8/dist-packages/parameterized/parameterized.py", line 136, in parameterized_argument_value_pairs
    argspec = inspect.getargspec(func)
  File "/usr/lib/python3.8/inspect.py", line 1083, in getargspec
    raise ValueError("Function has keyword-only parameters or annotations"
ValueError: Function has keyword-only parameters or annotations, use inspect.signature() API which can support them

While

def foo_bar_provider() -> List[List]:
    return [['foo'], ['bar']]

  @parameterized.expand(foo_bar_provider)
    def test_foo_bar(self, provider):

works as intended