Trying to take a command line argument (table_name) into pytest (via conftest.py, see below) and use that argument in a helper method to make a query in a DB, and then use query results to create parameterized test inputs using @pytest.mark.parametrize on a test_ function.
#contents of conftest.py
import pytest
def pytest_addoption(parser):
parser.addoption("--table_name", action="store", default=None, help="enter table name")
@pytest.fixture
def table_name(request):
return request.config.getoption('--table_name')
Problem is: the command line argument (table_name) is being retrieved using a fixture, and we'd like to pass this into a helper method to make a query and put the query results in a list, but since the helper method takes a fixture, it can't be called outside of another fixture/test_function. So we can't put the list into the parameterized test_function params
#helper method
def get_test_cases(table_name):
#connect to DB, makes query
#puts all query results into a list called tests
return tests
#test function
@pytest.mark.parametrize("columns...", (values...)) #list is read as values
def test_function(columns):
#assertion tests
Is there any way to use the command line argument and also pass the results of the DB query into the parameterized marker/params?