[TIP] User defined pytest parameter in setup

Fabian Cenedese Cenedese at indel.ch
Fri Mar 22 07:13:17 PDT 2019

At 14:54 22.03.2019, you wrote:

>Use the new `pytestconfig` fixture.
># --------- conftest.py
>def pytest_addoption(parser):
>    parser.addoption("--name", action="store", default="default name")
>#  ------- test_param.py 
>import pytest
>def name(pytestconfig):
>    return pytestconfig.getoption("name")
>def test_print_name(name):
>        print(f"\ncommand line param (name): {name}")

I have already seen the example with normal test functions. But I want
to use the value in the setup function which is defined as

def setup_module(module):

so I can't add the fixture there. How I can use the value in the setup?


bye  Fabi

More information about the testing-in-python mailing list