我有一个灯具,我有几个参数。我想使用两个参数来测试某些功能,但是我想将某些测试限制为仅使用参数之一。我以为pytest.mark.parametrize
在这里可能会有所帮助,但似乎只是将值传递到函数中,而不是夹具中。
这就是我所拥有的,我想在评论中进行:
@pytest.fixture(params=[sa_config, oauth_config], ids=["service_account", "oauth"])
def config(request, tmpdir_factory):
f = tmpdir_factory.mktemp("conf").join("google_secret.json")
f.write(json.dumps(request.param))
return os.path.split(f)
# Pass only "oauth" (oauth_config) to the config fixture
# tried @pytest.mark.parametrize("config", [oauth_config]) here to no avail
@pytest.fixture
def set_oauth_config(config):
os.environ[conf.CONFIG_DIR_ENV_VAR] = config[0]
# Pass only "service_account" (sa_config) to the config fixture
@pytest.fixture
def set_sa_config(config):
os.environ[conf.CONFIG_DIR_ENV_VAR] = config[0]
def test1(config):
# run test for loading both configs
assert config
def test2(set_sa_config):
# run a test on a function which will read the 'default' config and should use a service account
pass