小编meh*_*etg的帖子

将命令行参数作为参数传递给py.test fixture

不可否认,这不是开始时最好的方法,更重要的是解决了夹具参数,即在其他一切之前调用Options.get_option().建议和建议将不胜感激.

来自config.py

class Options(object):
    option = None

    @classmethod
    def get_option(cls):
        return cls.option
Run Code Online (Sandbox Code Playgroud)

来自conftest.py

@pytest.yield_fixture(scope='session', autouse=True)
def session_setup():
    Options.option = pytest.config.getoption('--remote')

def pytest_addoption(parser):
    parser.addoption("--remote", action="store_true", default=False, help="Runs tests on a remote service.")




@pytest.yield_fixture(scope='function', params=Options.get_option())
def setup(request):
    if request.param is None:
        raise Exception("option is none")
Run Code Online (Sandbox Code Playgroud)

python pytest

7
推荐指数
1
解决办法
6397
查看次数

标签 统计

pytest ×1

python ×1