简体   繁体   中英

pytest can't find pytest.fixture_request

I am attempting to utilize the alternative approach listed in the PyTest documentation here. My parametrize decorator call looks like this

@pytest.mark.parametrize("val1, params, result", [
    ('a string', pytest.fixture_request('valid_type'), 150)

])

However, when I run pytest I get the following error:

test_get_responses.py:102: in <module>
    ('a string', pytest.fixture_request('valid_type'), 150)
E   AttributeError: 'module' object has no attribute 'fixture_request'

The valid_type fixture does exist.

I am running pytest version 3.2.0

How can I solve this problem, so that I can utilize the 'alternative approach' listed in the documentation above?

The described approach is only a proposal that has not been implemented yet (as you can see in this discussion: https://github.com/pytest-dev/pytest/issues/349#issuecomment-286451346 ). As a workaround, you can use the package pytest-lazy-fixture (can be installed with pip ): instead of pytest.fixture_request('fixture_name') just use pytest.lazy_fixture('fixture_name') .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM