python - Can I add ini style configuration to pytest suites? -


i using pytest run tests in multiple environments , wanted include information (ideally) in ini style config file. override parts or of configuration @ command line well. tried using hook pytest_addoption in conftest.py so:

def pytest_addoption(parser):     parser.addoption("--hostname", action="store", help="the host")     parser.addoption("--port", action="store", help="the port")  @pytest.fixture def hostname(request):     return request.config.getoption("--hostname")  @pytest.fixture def port(request):     return request.config.getoption("--port") 

using can add configuration info @ command line, not in config file. tried adding

[pytest] addopts = --hostname host --port 311 

to pytest.ini file, didn't work. there way without building own plugin? time.

the parser object have addini method can use specify configuration options through ini file. here documentation it: https://pytest.org/latest/writing_plugins.html?highlight=addini#_pytest.config.parser.addini

addini(name, help, type=none, default=none)[source] registers ini-file option.

name: name of ini-variable

type: type of variable, can pathlist, args, linelist or bool.

default: default value if no ini-file option exists queried.

the value of ini-variables can retrieved via call config.getini(name).


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -