I have the following test code:
class TestMyCode(unittest.TestCase): @pytest.mark.parametrize('item', [5,4,10]) def test_valid_range(self, item): self.assertTrue(1 <= item <= 1000)
This is not my real test this is just a minimal reproduce example.
I need to parameterised only the input which is checked against the same code.
For some reason this doesn’t work I always get:
TypeError: test_valid_range() missing 1 required positional argument: 'item'
How can I fix it?
Advertisement
Answer
You can’t use @pytest.mark.parametrize
on unittest.TestCase methods
. PyTest has no way to pass in the parameter.
Just do:
@pytest.mark.parametrize('item', [5,4,10]) def test_valid_range(item): self.assertTrue(1 <= item <= 1000)