5

I'm trying to learn pytest, and I'm having a hard time understanding the behavior of parameterize().

import pytest

@pytest.mark.parameterize("foo", [1, 2, 3, 4, 5, 6, 7, ])
def test(foo):
    assert foo % 2 == 0

Running py.test on this returns an error: 'fixture 'foo' not found'.

Running this nearly identical example code works perfectly fine! What's the difference, why is my attempt at using parametrize failing?

import pytest

@pytest.mark.parametrize("blarg,argle", [("3+5", 8), ("2+4", 6), ("6*9", 42), ])
def test_eval(blarg, argle):
    assert eval(blarg) == argle
1
  • I disagree actually, because pytest does not alert you that you are misspelling something. (And in fact parameterize is a valid alternate spelling in English)
    – Dave
    Jan 13, 2015 at 19:20

1 Answer 1

9

Unfortunately it's just a typo in parametrize word,

import pytest

@pytest.mark.parametrize("foo", [1, 2, 3, 4, 5, 6, 7, ])
def test(foo):
    assert foo % 2 == 0

works great.

2
  • 1
    Oh...wow. That wasted a lot of time....heh. Mar 10, 2014 at 22:59
  • 1
    Newer versions of pytest will now show this error message: MarkerError: test has 'parameterize', spelling should be 'parametrize'
    – mbarkhau
    Jul 30, 2015 at 13:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.