I was hoping the following test would run 6 times...
test_example.py:
import pytest
@pytest.fixture(params=['a', 'b', 'c'])
def letters(request):
return request.param
@pytest.fixture(params=[1, 2, 3])
def numbers(request):
return request.param
@pytest.mark.parametrize('fixture', ['letters', 'numbers'])
def test_matrix(request, fixture):
assert request.getfixturevalue(fixture) in ['a', 'b', 'c', 1, 2, 3]
Pytest https://github.com/pytest-dev/pytest/commit/ba452dbcf01f16f1bdad1950c91977298588712d:
================ test session starts ================
platform linux -- Python 3.7.1, pytest-4.1.2.dev29+gba452dbc, py-1.7.0, pluggy-0.8.1
rootdir: /ifs/home/dtucker/Projects/pytest, inifile: tox.ini
collected 2 items
test_example.py FF [100%]
===================== FAILURES ======================
_______________ test_matrix[letters] ________________
The requested fixture has no parameter defined for test:
test_example.py::test_matrix[letters]
Requested fixture 'letters' defined in:
test_example.py:5
Requested here:
test_example.py:16
_______________ test_matrix[numbers] ________________
The requested fixture has no parameter defined for test:
test_example.py::test_matrix[numbers]
Requested fixture 'numbers' defined in:
test_example.py:10
Requested here:
test_example.py:16
============== short test summary info ==============
FAIL test_example.py::test_matrix[letters]
FAIL test_example.py::test_matrix[numbers]
============= 2 failed in 0.39 seconds ==============
pip list:
Package Version Location
-------------- --------------------- -------------------------------------
atomicwrites 1.2.1
attrs 18.2.0
more-itertools 5.0.0
pip 18.1
pluggy 0.8.1
py 1.7.0
pytest 4.1.2.dev29+gba452dbc /ifs/home/dtucker/Projects/pytest/src
setuptools 40.6.3
six 1.12.0
wheel 0.32.3
lsb_release -d:
Description: CentOS Linux release 7.6.1810 (Core)
Thats intentional
Please take a look at https://pypi.org/project/pytest-lazy-fixture, it supports your use case. 馃憤
Aha! Great, thanks 馃槉