Skip to content

pytest.mark.parametrize fails with lambdas #1111

Closed
@mithrandi

Description

@mithrandi

For example, the following:

import pytest
test = pytest.mark.parametrize('a', [1, 2, 3])(lambda a: None)

fails like this:

INTERNALERROR> Traceback (most recent call last):                                                                                                                                                                                     [1/950]
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/main.py", line 84, in wrap_session
INTERNALERROR>     doit(config, session)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/main.py", line 122, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/main.py", line 142, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 393, in execute
INTERNALERROR>     return wrapped_call(method(*args), self.execute)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 113, in wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 138, in get_result
INTERNALERROR>     py.builtin._reraise(*ex)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 123, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/runner.py", line 72, in runtestprotocol
INTERNALERROR>     rep = call_and_report(item, "setup", log)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 521, in __call__
INTERNALERROR>     return self._docall(self.methods, kwargs)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 528, in _docall
INTERNALERROR>     firstresult=self.firstresult).execute()
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 393, in execute
INTERNALERROR>     return wrapped_call(method(*args), self.execute)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 109, in wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/skipping.py", line 157, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 138, in get_result
INTERNALERROR>     py.builtin._reraise(*ex)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 123, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/core.py", line 394, in execute
INTERNALERROR>     res = method(*args)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/runner.py", line 227, in pytest_runtest_makereport
INTERNALERROR>     style=item.config.option.tbstyle)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/python.py", line 618, in _repr_failure_py
INTERNALERROR>     style=style)
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/main.py", line 392, in _repr_failure_py
INTERNALERROR>     return excinfo.value.formatrepr()
INTERNALERROR>   File "/home/mithrandi/deployment/virtualenvs/tempenv-1936316730d88/local/lib/python2.7/site-packages/_pytest/python.py", line 1540, in formatrepr
INTERNALERROR>     lines, _ = inspect.getsourcelines(function)
INTERNALERROR>   File "/usr/lib/python2.7/inspect.py", line 690, in getsourcelines
INTERNALERROR>     lines, lnum = findsource(object)
INTERNALERROR>   File "/usr/lib/python2.7/inspect.py", line 526, in findsource
INTERNALERROR>     file = getfile(object)
INTERNALERROR>   File "/usr/lib/python2.7/inspect.py", line 420, in getfile
INTERNALERROR>     'function, traceback, frame, or code object'.format(object))
INTERNALERROR> TypeError: <MarkDecorator 'parametrize' {'args': ('a', [1, 2, 3], <function <lambda> at 0x7fbd7d56aaa0>), 'kwargs': {}}> is not a module, class, method, function, traceback, frame, or code object

This reproducer may seem rather odd by itself, but something like this may arise with a decorator that returns a lambda.

I have confirmed this failure on pytest 2.7.0, 2.7.3, 2.8.0, and 2.8.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: parametrizerelated to @pytest.mark.parametrizetype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions