Skip to content Skip to sidebar Skip to footer

How To Pass Testcase Value To Next One With Pytest

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', testDat

Solution 1:

Not exactly sure why it didn't work, but doing it like that it's a bad idea since the order of tests is not guaranteed (unless you implement ad-hoc code to order the execution of tests).

Besides this and other issues of test design, the way you can somewhat achieve what you want would be by joining testData1 and testData2 in the pytest.mark.parametrize decorator.

@pytest.mark.parametrize('n', testData1 + testData2)deftest_sub(self, n):
    result = sub(n)
    assert result == 3

Now, keep in mind that with your test definition, this will always fail because the result of sub(n) with testData1 + testData2 will never be 3.

Post a Comment for "How To Pass Testcase Value To Next One With Pytest"