If you want to pass an argument to a fixture, you should use the Factory as Fixture pattern, as explained in the documentation:
@pytest.fixture(scope='function')
def my_setup():
def _my_setup(arg2=None)
execute_setup_actions(arg2)
return _my_setup
And then, on your test:
@pytest.mark.parametrize('name, arg1', [
('test_1', 1),
...
('test_100', 100),
])
def test_mine(name, arg1, my_setup):
my_setup(arg2)
execute_test_case(arg1)
Instead of adding arg2 to the parametrize marker as you suggested, you could just write another test, but, as you would have only one value for arg2, you wouldn't need to parametrize it:
@pytest.mark.parametrize('name, arg1', [
('test_1', 1),
...
('test_100', 100),
])
def test_mine1(name, arg1):
execute_test_case(arg1)
def test_mine2(name):
execute_test_case(arg1, arg2)
Please note that there is no value for the name fixture on the second test because it's not being used on the first one (more on that below).
Now, there are some inconsistencies with your code:
- The
my_setup fixture is not being used. You should add the autouse=True option or add it to the test signature.
- You're not using the
name parameter on your test.
- Would the
name parameter be the test id? You could then use the id option on the parametrize marker (more here).
So, based on your needs and the issues I saw, I would refactor your tests like this:
names_list = ['test_1' ... 'test_100']
arg1_list = [1 ... 100]
@pytest.mark.parametrize('arg1', arg1_list, ids=names_list)
def test_mine1(arg1):
execute_test_case(arg1)
def test_mine2():
execute_test_case(arg1, arg2)