我在 confttest.py 中包含了我自己的命令行选项
def pytest_addoption(parser):
parser.addoption("--backend" , default="test_backend",
help="run testx for the given backend, default: test_backend")
和
def pytest_generate_tests(metafunc):
if 'backend' in metafunc.funcargnames:
if metafunc.config.option.backend:
backend = metafunc.config.option.backend
backend = backend.split(',')
backend = map(lambda x: string.lower(x), backend)
metafunc.parametrize("backend", backend)
如果我在模块内的普通函数中使用此命令行选项:
module: test_this.py;
def test_me(backend):
print backend
它按预期工作。
现在我想在一些测试之前包含 setup_module 函数来创建/复制一些东西:
def setup_module(backend):
import shutil
shutil.copy(backend, 'use_here')
...
不幸的是,我现在知道如何在 setup_module 函数中访问此命令行选项。没有任何效果,我试过了。
感谢您的帮助,建议。
干杯