I have the following test code:
JavaScript
x
5
1
class TestMyCode(unittest.TestCase):
2
@pytest.mark.parametrize('item', [5,4,10])
3
def test_valid_range(self, item):
4
self.assertTrue(1 <= item <= 1000)
5
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:
JavaScript
1
2
1
TypeError: test_valid_range() missing 1 required positional argument: 'item'
2
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:
JavaScript
1
4
1
@pytest.mark.parametrize('item', [5,4,10])
2
def test_valid_range(item):
3
self.assertTrue(1 <= item <= 1000)
4