I've been trying to solve a python test using pytest but have not been able to find an example configuration that works - though some are close. Here is my case study:
@pytest.fixture
def vil_check():
code
return [(v1,v2,v3), (...), (...)]
@pytest.mark.parameterize("v1,v2,v3", vil_check):
def test_one(v1,v2,v3):
assert v1 < 2
assert v2 > 5
....
I'm trying to follow this example:
@pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)])
def test_eval(test_input, expected):
assert eval(test_input) == expected
But using a fixture to supply the list: [("3+5", 8), ("2+4", 6), ("6*9", 42)].
However, this configuration doesn't work:
@pytest.mark.parametrize("v1, v2, v3", vil_check)
def test_max(v1, v2, v3):
assert abs(v1) <= 5
The error is that pytest doesn't see vil_check return as iterable.
There seems to be a way to use pytest_generate_tests to accomplish this but I'm drawing a blank on how to write it.
pytest.mark.parametrize, nor can you use it inpytest_generate_tests. Is there a reason why you need a fixture and cannot just use a function here?vil_check. This information can will varying which is why I need to parameterize the test so that the number of tests run equals the number of values returned byvil_check. How can I do this using pytest?vil_checkto be a fixture. Is it like it's being used elsewhere as well?pytest.mark.parametrize. I'm asking how to do this given the nature of the case study.