I want to add a custom command-line flag to pytest which is responsible for setting multiple command-line options in conftest.py. (I don't want to set these options in pyproject.toml)
So basically, I want the following two commands too be equivalent
pytest -o log_cli=1 -o log_cli_level=10 -o log_format="%(message)s"
pytest --vmtrace
Now I have figured out how to register the --vmtrace option inside conftest.py as well as how I can access the value passed to it.
I am however, unable to figure out how to set the values of the log_cli log_cli_level and log_format options as required in the command above.
Here is what my conftest.py file currently looks like. Please suggest, what should replace the comments in the pytest_configure function.
def pytest_addoption(parser):
parser.addoption("--vmtrace", dest='vmtrace', default=1, action='store_const', const=10, help="Run trace")
def pytest_configure(config):
if config.getoption("vmtrace", default=1) == 10:
# Set the log_cli option to 1
# Set the log_cli_level option to 10
# Set the log_format option to "%(message)s"