This question is similar to How to Parametrize a Pytest Fixture but I'd like to go a step further. Here's what I have so far:
import pytest
class TimeLine:
def __init__(self, s, instances=[0, 0, 0]):
self.s = s
self.instances = instances
@pytest.fixture(params=[
('foo', [0, 2, 4, 0, 6]),
('bar', [2, 5]),
('hello', [6, 8, 10])
])
def timeline(request):
return TimeLine(request.param[0], request.param[1])
This works
def test_timeline(timeline):
for instance in timeline.instances:
assert instance % 2 == 0
I would like to create a parameterized test for the length of instances
.
@pytest.mark.parametrize('length', [
(5), (1), (3)
])
def test_timeline(length, timeline):
assert len(timeline.instances) == length
There should be 3 tests. The first and the last tests should pass. The second test should fail. How would I set up the test to do this?