Dragan R.
Dragan R.

Reputation: 670

pytest AttributeError: Metafunc instance has no attribute 'parameterize'

I am trying to parameterize my tests using pytest. I modified my conftest.py file to parameterize the fixture via pytest_generate_tests hook, and added the fixture itself:

def pytest_generate_tests(metafunc):
    data = []
    with open('/tmp/search_terms.csv') as search_terms:
        while True:
            term = search_terms.readline().rstrip()
            if not term:
                break            
            data.append(term)

    if 'search_term' in metafunc.fixturenames:
        metafunc.parameterize("search_term", data)

@pytest.fixture(scope="session")
def search_term(request):
    return request.param

For now, I just want the test to print out my search_term.csv content and pass:

def test_print_search_term(search_term):
    print search_term

However, I get the following error:

test_search_terms.py:None (test_search_terms.py)
conftest.py:34: in pytest_generate_tests
    metafunc.parameterize("search_term", data)
    E   AttributeError: Metafunc instance has no attribute 'parameterize'

My goal: I want to read from this csv, and parameterize my test (and many other tests) based on the values in this CSV. I'm not understanding why Metafunc.parameterize is not being picked up. Do I need to install something separately?

Also, is there a better way to accomplish this (i.e. parameterizing multiple tests from a csv file?)

Upvotes: 2

Views: 1772

Answers (1)

theY4Kman
theY4Kman

Reputation: 6125

py.test spells it "parametrize" (no "e" after the "t")

Upvotes: 3

Related Questions