pytest.mark.parametrize
is not intended to be used in this way.
with pytest_addoption of pytest you can inject yours a, b parameters using metafunc.parametrize
using this technique allow you to set also parameters in environment variables.
conftest.py
def pytest_addoption(parser):
parser.addoption("--a", action="store")
parser.addoption("--b", action="store")
def pytest_generate_tests(metafunc):
for par_name, par_value in (
('a',metafunc.config.option.a),
('b',metafunc.config.option.b)
):
if par_name in metafunc.fixturenames and par_value:
metafunc.parametrize(par_name, [par_value])
test_sample.py
def test_c1(a, b):
assert a == b
CLI
$ pytest test_sample.py --a 42 --b 42
collected 1 item
test_sample.py . [100%]
= 1 passed in 0.01s =
$ pytest test_sample.py --a 42 --b 24
collected 1 item
test_sample.py F [100%]
= FAILURES =
_ test_c1[42-24] _
a = '42', b = '24'
def test_c1(a, b):
> assert a == b
E AssertionError: assert '42' == '24'
E - 24
E + 42
test_sample.py:2: AssertionError
================================================================================== short test summary info ==================================================================================
FAILED test_sample.py::test_c1[42-24] - AssertionError: assert '42' == '24'
===================================================================================== 1 failed in 0.07s
Something similar here: How to pass arguments in pytest by command line