I am trying to pass command line arguments to pytest tests. Example from this question
print ("Displaying name: %s" % name)
In conftest
parser.addoption("--name", action="store", default="default name")
def pytest_generate_tests(metafunc):
# This is called for every test. Only get/set command line arguments
# if the argument is specified in the list of test "fixturenames".
option_value = metafunc.config.option.name
if 'name' in metafunc.fixturenames and option_value is not None:
metafunc.parametrize("name", [option_value])
I want to pass name argument to pytest.mark.parametrize. Now, I am aware that according to the question I've referenced, the answer mentions that I shouldn't use @pytest.mark.parametrize. However, I am working on a code base that already utilizes it and I also need to pass arguments as part of CI process. Is there a work around or am I doomed to re-write all of the tests?
Edit: Since I wasn't clear enough- I cannot use the command line argument in mark.parametrize with pytest console line args. Example- I have a function that returns a list and has input for name and I add it to the mark.parametrize:
@pytest.mark.parametrize("return_list", foo(name)):
def test_name(return_list):
pass
The name parameter, like I mentioned needs to come from the command line, and this doesn't work in any method that I've encountered. I don't know how to use a list in pytest without mark.parametrize, so it's a problem