py.test parametrize `pytest.param` not found?

Viewed 1343

While trying to make unit tests (using py.test) more generic I am generating the test programatically. - I've a function that exports the arguments and the invariant that holds at the end of the test.

Now to keep things tidy I also wish to pass an ID for the test. Looking through the official(?) documentation for pytest I notice:

import pytest

from datetime import datetime, timedelta

# ...

@pytest.mark.parametrize("a,b,expected", [
    pytest.param(datetime(2001, 12, 12), datetime(2001, 12, 11),
                 timedelta(1), id='forward'),
    pytest.param(datetime(2001, 12, 11), datetime(2001, 12, 12),
                 timedelta(-1), id='backward'),
])
def test_timedistance_v3(a, b, expected):
    diff = a - b
    assert diff == expected

at examples to show different ways to parametrize.

Above method is exactly what I wish to do (give arguments and also ID with each set of arguments): my function would just output a list of pytest.param objects. However when I ran the above snippet (or full one from pytest.org) I'm given the following error (also pycharm ide highlights this syntax error):

E AttributeError: module 'pytest' has no attribute 'param'

Is the documentation wrong? Am I missing something where I don't have the environment set up correctly?

1 Answers
Related