Reputation: 93
Let's say we have a test class with test function:
class TestMyTestClass:
@pytest.fixture(scope="class", autouse=True):
def setup_my_tests(self, request):
request.cls.int_list = [1, 2, 3, 4, 5]
yield
@pytest.mark.parametrize('my_number', self.int_list)
def test_check_for_odd(self, my_number):
assert my_number % 2 == 0
This^ will not work. I can't use test class attribute self.int_list
as parameter for pytest.mark.parametrize()
.
No, I can't do : @pytest.mark.parametrize('my_number', [1, 2, 3, 4, 5])
. That list needs to be generated in class or using class attributes.
Is there a way to pass class attribute to pytest.mark.parametrize
?
Upvotes: -2
Views: 73