Is it possible to add more than one option in the command line for pytest?
I see that I can add the pytest_addoption
hook to the conftest.py file, but I'm wondering how to go about adding more than one option(s).
You can specify arbitrarily many command-line options using the pytest_addoption
hook.
Per the pytest hook documentation:
Parameters: parser – To add command line options, call parser.addoption(...). To add ini-file values call parser.addini(...).
The pytest_addoption
hook is passed a parser
object. You can add as many command-line options as you want by calling parser.addoption(...)
as many times as you want.
So an example of adding two parameters is as simple as:
def pytest_addoption(parser):
parser.addoption('--foo', action='store_true', help='Do foo')
parser.addoption('--bar', action='store_false', help='Do not do bar')
And like any other py.test hook this needs to go into a conftest.py file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With