I have an array of objects that I need to run for each test inside my test class. I want to parametrize every test function in a TestClass. The end goal is to have something resembling:
@pytest.mark.parametrize('test_input', [1, 2, 3, 4])
class TestClass:
def test_something1(self, test_input):
# test code here, runs each time for the parametrize
But from my understanding, you can't pass input parameters, or at least call @pytest.mark.parametrize
on a class, those markers are meant for defs
not class
s
What I have now:
class TestClass:
def test_something1(self):
for i in stuff:
# test code here
def test_something2(self):
for i in stuff:
# test code here
...
Is there a way to pass the parametrize a class itself or every function inside the TestClass? Maybe a @pytest.mark.parametrize
inside a @pytest.fixture...(autouse=True).
I want to keep my tests organized as a class because it mirrors the file that I'm testing. Because I loop through these objects in at least a dozen different tests, it would be easier to call a loop of the class than in each def
.