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 - as a fixture

  • conftest

  • We can also create a fixture that will read the parameter

import pytest

def pytest_addoption(parser):
    parser.addoption("--demo")

@pytest.fixture
def mydemo(request):
    return request.config.getoption("--demo")
def test_me(mydemo):
    print(mydemo)
pytest -s
test_one.py None
pytest -s --demo Hello
test_one.py Hello