Saturday, 9 July 2022

Optional argument in pytest.mark.parametrize

I have a long test with pytest framework. The code is like this:

@pytest.fixture(scope='function')
def my_setup():
        execute_setup_actions()

@pytest.mark.parametrize('name, arg1', [
        ('test_1', 1),
        ...
        ('test_100', 100),
])
def test_mine(name, arg1):
         execute_test_case(arg1)

Now I need an optional argument arg2 for my_setup fixture my_setup(arg2=None) used in one new test written in @pytest.mark.parametrize. Certainly I can put 'name, arg1, arg2' in parametrize and add None argument values for other 100 tests, but is there any other method to do such a thing in a more pretty way?

Thanks!



from Optional argument in pytest.mark.parametrize

No comments:

Post a Comment