How send a config variable to a py.test test?

旧城冷巷雨未停 提交于 2019-12-05 16:38:56

Using pytest_addoption:

test_blah.py

def test_something(mode):
    if mode == 'ALPHA':
        assert True
    else:
        assert False

conftest.py

import pytest

def pytest_addoption(parser):
    parser.addoption("--set-mode", action="store", default="ALPHA",
                                help="ALPHA or BETA")

@pytest.fixture
def mode(request):
    return request.config.getoption("--set-mode")

See Pass different values to a test function, depending on command line options.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!