In conftest.py:

1
2
3
4
def pytest_addoption(parser):
parser.addoption(
"--test_mode", action="store", default=None, help="my option: type1 or type2"
)
1
2
3
@pytest.fixture
def test_mode(request):
return request.config.getoption("--test_mode")

In config.py:

1
2
3
4
5
6
config_dict = {
"sql": TestMode.SQL,
"data": TestMode.DATA,
"update_sql": TestMode.UPDATE_SQL,
"update_data": TestMode.UPDATE_DATA
}

For different test case executions:

1
2
3
4
5
6
7
8
def run_query(self, scope, query_func, *args):
query = query_func(scope, *args)

if self._mode == TestMode.SQL:
...
elif self._mode == TestMode.DATA:
...
...

For command line test usage:

1
2
3
4
pytest -q tests/test_derived.py --test_mode=update_sql
pytest -q tests/test_derived.py --test_mode=sql
pytest -q tests/test_derived.py --test_mode=update_data
pytest -q tests/test_derived.py --test_mode=data

For more information and easier examples, click here