Add extra command line parameters to Pytest - conftest - getoption
In the conftest.py file we can use the pytest_addoption function to defined new command line options.
--demoexpects a value.--noisyis a boolean flag. By default it is false.
In the tests we need to use the request fixture and the getoption method to get the value of each option
def pytest_addoption(parser):
parser.addoption("--demo")
parser.addoption("--noisy", action='store_true')
def test_me(request):
print(request.config.getoption("--demo"))
print(request.config.getoption("--noisy"))
pytest -s
None
False
pytest -s --demo Hello --noisy
Hello
True