I have parameterized pytest tests. How to add an additional parameter to the tests that is passed to pytest as a command line argument?
I tried adding an option xyz to the parser and put return the command line argument as a fixture, like so..
conftest.py:
def pytest_addoption(parser):
parser.addoption(
"--some_other_option", action="store_true", default=True, help="Skip some tests"
)
parser.addoption(
"--xyz", action="store_true", default=True, help="Test xyz"
)
@pytest.fixture
def xyz(config):
return config.getoption('--xyz')
test file:
@pytest.mark.parametrize('arg1, arg2, arg3, arg4, arg5', [
(asdf', 1, 1, 0, [0.64]),
...
])
def test_stuff(arg1, arg2, arg3, arg4, arg5, xyz):
if xyz: # only do this if xyz is True
assert func(arg3) == 42
....
I have also tried it like this.
In both cases, the issue is that pytest returns an error for every test
`E fixture 'config' not found
What am I doing wrong? `