import pytest
def add(x):
return x + 1
def sub(x):
return x - 1
testData1 = [1, 2]
testData2 = [3]
class Test_math(object):
@pytest.mark.parametrize('n', testData1)
def test_add(self, n):
result = add(n)
testData2.append(result) <-------- Modify testData here
assert result == 5
@pytest.mark.parametrize('n', testData2)
def test_sub(self, n):
result = sub(n)
assert result == 3
if __name__ == '__main__':
pytest.main()
there are only 3 tests :Test_math.test_add[1]
,Test_math.test_add[2]
,Test_math.test_sub[3]
executed in this scenario.
Test_math.test_sub
only executes with predefined data [3]
which is not my expectation [2,3,3]
. How to fix it?
update [1,2,3]-> [2,3,3]