Tuesday, March 6, 2012

py.test paremeterized test fails with "LookupError: no factory found for function argument …"


I have a trivial test:
import pytest
@pytest.mark.parameterize(("input", "expected"), [
    ("3+5", 8),
    ("2+4", 6),
    ("6*9", 42),
])
def test_eval(input, expected):
    assert eval(input) == expected
It fails saying:
LookupError: no factory found for function argument 'input'
available funcargs: pytestconfig, capsys, capfd, tmpdir, monkeypatch, recwarn
use 'py.test --funcargs [testpath]' for help on them.
What's going on here? It's spelt parametrize – not parameterize.

But why didn't I get a NameError?

pytest.mark allows arbitrary marks to be added to a function. Due to the
dynamic nature of py.test, pytest.mark.<any name here> can be used to mark a
test. Since pytest.mark.parameterize isn't recognised by any of the pytest
plugins, it's essentially a no-op.

No comments:

Post a Comment