Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Add extra command line parameters to Pytest - conftest - getoption

  • conftest

  • In this case the option expects a value

  • And we need to use getoption to get the value

  • See Parser

  • See argparse

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