pytest parametrize: How to pair specific inputs with corresponding expected outputs using fixtures?

68 views Asked by At

I'm trying to use pytest's parametrize decorator to pair specific inputs with corresponding expected outputs and using fixtures for input values inside decorator. For example, I want to match the input '56r 4j' with the expected output ['56r 4j'] and '5d 4s' with ['5d 4s'].
@pytest.fixture(params=['56r 4j', '5d 4s']) def fixture_Sample1(request): inputVal = np.array(request.param) return inputVal

@pytest.fixture(params=[['56r 4j'], ['5d  4s']])
def fixture_Sample2(request):
    expectedVal = request.param
    return expectedVal


@pytest.mark.parametrize('input,expected_output', [
    (pytest_lazyfixture.lazy_fixture('fixture_Sample1'), pytest_lazyfixture.lazy_fixture('fixture_Sample2'))])
def test_val(input,expected_output):
    print('input is ' ,input)
    print('expected output ',expected_output)

However, I'm encountering an issue where each input is getting paired with each output, resulting in four cases instead of the intended two. The output can be seen in this snapshot: [1]: https://i.stack.imgur.com/5BBLL.png

How can I modify my parametrize setup to achieve the desired pairing and get only two test cases?

0

There are 0 answers