I know that there is a way to pass args in tests itself like it was shown here, but is there a way to pass in conftest.py directly? I want to configure some common stuff for all tests this way.

1 Answer 1


You can make something like this:

File: conftest.py

option = None

def pytest_addoption(parser):
    parser.addoption("--arg", action="store", default="example", help="Option for making some stuff")

def pytest_configure(config):
    global option
    option = config.option

and you can access your argument with option.arg in your conftest file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.