本文整理汇总了Python中utils.testgen.parametrize函数的典型用法代码示例。如果您正苦于以下问题:Python parametrize函数的具体用法?Python parametrize怎么用?Python parametrize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parametrize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pytest_generate_tests
def pytest_generate_tests(metafunc):
types = [VMwareProvider, RHEVMProvider, SCVMMProvider]
argnames, argvalues, idlist = testgen.providers_by_class(
metafunc, types)
argnames = ['providers_for_discover', 'start_ip', 'max_range']
new_id_list = []
providers_complete = []
providers_final = []
for x in idlist:
providers_complete.append(get_crud(x))
provider_combinations = sorted(
find_neighbour_provider_combinations(providers_complete, len(types)), key=len)
signatures_seen = set()
for prov_comb in provider_combinations:
sig = generate_signature(prov_comb)
if sig in signatures_seen:
continue
signatures_seen.add(sig)
start_ip, max_range = minmax_ip(prov_comb)
providers_final.append([prov_comb, start_ip, max_range])
new_id_list.append(sig)
testgen.parametrize(metafunc, argnames, providers_final, ids=new_id_list, scope="module")
示例2: pytest_generate_tests
def pytest_generate_tests(metafunc):
argnames = ['reg_method', 'reg_data', 'proxy_url', 'proxy_creds']
argvalues = []
idlist = []
all_reg_data = conf.cfme_data['redhat_updates']['registration']
if 'reg_method' in metafunc.fixturenames:
for reg_method in REG_METHODS:
reg_data = all_reg_data.get(reg_method, None)
if not reg_data or not reg_data.get('test_registration', False):
continue
proxy_data = all_reg_data.get('http_proxy', False)
if proxy_data and proxy_data.get('url', None):
proxy_url = proxy_data['url']
proxy_creds = conf.credentials['http_proxy']
argval = [reg_method, reg_data, proxy_url, proxy_creds]
argid = '{}-{}'.format(reg_method, 'proxy_on')
idlist.append(argid)
argvalues.append(argval)
argval = [reg_method, reg_data, None, None]
argid = '{}-{}'.format(reg_method, 'proxy_off')
idlist.append(argid)
argvalues.append(argval)
parametrize(metafunc, argnames, argvalues, ids=idlist, scope="module")
示例3: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.infra_providers(metafunc, 'provisioning')
argnames = argnames + ['cloud_init_template']
new_idlist = []
new_argvalues = []
for i, argvalue_tuple in enumerate(argvalues):
args = dict(zip(argnames, argvalue_tuple))
if not args['provisioning']:
# No provisioning data available
continue
if args['provider_type'] == "scvmm" or args['provider_type'] == 'virtualcenter':
continue
# required keys should be a subset of the dict keys set
if not {'ci-template', 'ci-username', 'ci-pass', 'template'}.issubset(
args['provisioning'].viewkeys()):
continue
cloud_init_template = args['provisioning']['ci-template']
if cloud_init_template not in cfme_data.get('customization_templates', {}).keys():
continue
argvalues[i].append(get_template_from_config(cloud_init_template))
new_idlist.append(idlist[i])
new_argvalues.append(argvalues[i])
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
示例4: pytest_generate_tests
def pytest_generate_tests(metafunc):
new_idlist = []
new_argvalues = []
argnames, argvalues, idlist = testgen.provider_by_type(
metafunc, PROVIDER_TYPES, required_fields=['datastores'])
argnames += ['datastore']
for i, argvalue_tuple in enumerate(argvalues):
args = dict(zip(argnames, argvalue_tuple))
datastores = args['provider'].data.get('datastores', {})
if not datastores:
continue
for ds in datastores:
if not ds.get('test_fleece', False):
continue
assert ds.get('type', None) in DATASTORE_TYPES,\
'datastore type must be set to [{}] for smartstate analysis tests'\
.format('|'.join(DATASTORE_TYPES))
argvs = argvalues[i][:]
new_argvalues.append(argvs + [datastore.Datastore(ds['name'], args['provider'].key,
ds['type'])])
test_id = '{}-{}'.format(args['provider'].key, ds['type'])
new_idlist.append(test_id)
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
示例5: pytest_generate_tests
def pytest_generate_tests(metafunc):
types = ["virtualcenter", "rhevm", "scvmm"]
argnames, argvalues, idlist = testgen.provider_by_type(metafunc, types)
argnames = ["providers_for_discover", "start_ip", "max_range"]
new_id_list = []
providers_complete = []
providers_final = []
for x in idlist:
providers_complete.append(get_crud(x))
provider_combinations = sorted(find_neighbour_provider_combinations(providers_complete, len(types)), key=len)
signatures_seen = set()
for prov_comb in provider_combinations:
sig = generate_signature(prov_comb)
if sig in signatures_seen:
continue
signatures_seen.add(sig)
start_ip, max_range = minmax_ip(prov_comb)
providers_final.append([prov_comb, start_ip, max_range])
new_id_list.append(sig)
testgen.parametrize(metafunc, argnames, providers_final, ids=new_id_list, scope="module")
示例6: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.infra_providers(metafunc)
if not idlist:
return
new_idlist = []
new_argvalues = []
if 'random_pwr_ctl_vm' in metafunc.fixturenames:
if random_vm_test:
# Reusing random vm for test
argnames, new_argvalues, new_idlist = random_vm_test
else:
# Picking random VM for tests
single_index = random.choice(range(len(idlist)))
new_idlist = ['random_provider']
new_argvalues = argvalues[single_index]
argnames.append('random_pwr_ctl_vm')
new_argvalues.append('')
new_argvalues = [new_argvalues]
random_vm_test.append(argnames)
random_vm_test.append(new_argvalues)
random_vm_test.append(new_idlist)
else:
new_idlist = idlist
new_argvalues = argvalues
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="class")
示例7: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.infra_providers(
metafunc,
required_fields=[["provisioning", "template"], ["provisioning", "host"], ["provisioning", "datastore"]],
)
testgen.parametrize(metafunc, argnames, argvalues, ids=idlist, scope="module")
示例8: pytest_generate_tests
def pytest_generate_tests(metafunc):
argnames, argvalues, idlist = testgen.providers_by_class(metafunc, [InfraProvider])
argnames = argnames + ['host_type', 'host_name']
new_argvalues = []
new_idlist = []
for i, argvalue_tuple in enumerate(argvalues):
args = dict(zip(argnames, argvalue_tuple))
prov_hosts = args['provider'].data['hosts']
if not prov_hosts:
continue
for test_host in prov_hosts:
if not test_host.get('test_fleece', False):
continue
assert test_host.get('type', None) in HOST_TYPES,\
'host type must be set to [{}] for smartstate analysis tests'\
.format('|'.join(HOST_TYPES))
argvalues[i] = argvalues[i] + [test_host['type'], test_host['name']]
test_id = '{}-{}-{}'.format(args['provider'].key, test_host['type'], test_host['name'])
new_argvalues.append(argvalues[i])
new_idlist.append(test_id)
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
示例9: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.infra_providers(
metafunc, 'provisioning', template_location=["provisioning", "template"])
new_idlist = []
new_argvalues = []
for i, argvalue_tuple in enumerate(argvalues):
args = dict(zip(argnames, argvalue_tuple))
if not args['provisioning']:
# No provisioning data available
continue
if args['provider'].type == "scvmm":
continue
# required keys should be a subset of the dict keys set
if not {'template', 'host', 'datastore'}.issubset(args['provisioning'].viewkeys()):
# Need all three for template provisioning
continue
new_idlist.append(idlist[i])
new_argvalues.append(argvalues[i])
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
示例10: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.infra_providers(metafunc, required_fields=[
'iso_datastore',
['provisioning', 'host'],
['provisioning', 'datastore'],
['provisioning', 'iso_template'],
['provisioning', 'iso_file'],
['provisioning', 'iso_kickstart'],
['provisioning', 'iso_root_password'],
['provisioning', 'iso_image_type'],
['provisioning', 'vlan'],
])
argnames = argnames + ['iso_cust_template', 'iso_datastore']
new_idlist = []
new_argvalues = []
for i, argvalue_tuple in enumerate(argvalues):
args = dict(zip(argnames, argvalue_tuple))
iso_cust_template = args['provider'].data['provisioning']['iso_kickstart']
if iso_cust_template not in cfme_data.get('customization_templates', {}).keys():
continue
argvalues[i].append(get_template_from_config(iso_cust_template))
argvalues[i].append(ISODatastore(args['provider'].name))
new_idlist.append(idlist[i])
new_argvalues.append(argvalues[i])
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
示例11: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.infra_providers(metafunc, 'provider_key')
for i, argvalue_tuple in enumerate(argvalues):
provider_data = cfme_data['management_systems'][
argvalue_tuple[argnames.index('provider_key')]]
if provider_data.get('type', False) != 'virtualcenter':
continue
if 'random_snpsht_mgt_vm' in metafunc.fixturenames:
if random_vm_test:
argnames, new_argvalues, new_idlist = random_vm_test
else:
single_index = random.choice(range(len(idlist)))
new_idlist = [idlist[single_index]]
new_argvalues = argvalues[single_index]
argnames.append('random_snpsht_mgt_vm')
new_argvalues.append('')
new_argvalues = [new_argvalues]
random_vm_test.append(argnames)
random_vm_test.append(new_argvalues)
random_vm_test.append(new_idlist)
else:
new_idlist = idlist
new_argvalues = argvalues
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
示例12: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without templates defined
argnames, argvalues, idlist = testgen.cloud_providers(metafunc, 'provisioning')
new_argvalues = []
new_idlist = []
for i, argvalue_tuple in enumerate(argvalues):
args = dict(zip(argnames, argvalue_tuple))
if not args['provisioning']:
# Don't know what type of instance to provision, move on
continue
# required keys should be a subset of the dict keys set
if not {'image'}.issubset(args['provisioning'].viewkeys()):
# Need image for image -> instance provisioning
continue
if metafunc.function in {
test_provision_from_template_with_attached_disks, test_provision_with_boot_volume,
test_provision_with_additional_volume} \
and args['provider_type'] != 'openstack':
continue
new_idlist.append(idlist[i])
new_argvalues.append([args[argname] for argname in argnames])
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
示例13: pytest_generate_tests
def pytest_generate_tests(metafunc):
argnames, argvalues, idlist = testgen.providers_by_class(metafunc, [VMwareProvider])
argnames = argnames + ["_host_provider"]
new_idlist = []
new_argvalues = []
for i, argvalue_tuple in enumerate(argvalues):
args = dict(zip(argnames, argvalue_tuple))
# TODO
# All this should be replaced with a proper ProviderFilter passed to testgen.providers()
if args['provider'].type != "virtualcenter":
continue
hosts = args['provider'].data.get("hosts", [])
if not hosts:
continue
version = args['provider'].data.get("version", None)
if version is None:
# No version, no test
continue
if Version(version) < "5.0":
# Ignore lesser than 5
continue
host = hosts[0]
creds = credentials[host["credentials"]]
ip_address = resolve_hostname(host["name"])
cred = VMwareProvider.Credential(
principal=creds["username"],
secret=creds["password"],
verify_secret=creds["password"]
)
# Mock provider data
provider_data = {}
provider_data.update(args['provider'].data)
provider_data["name"] = host["name"]
provider_data["hostname"] = host["name"]
provider_data["ipaddress"] = ip_address
provider_data["credentials"] = host["credentials"]
provider_data.pop("host_provisioning", None)
provider_data["hosts"] = [host]
provider_data["discovery_range"] = {}
provider_data["discovery_range"]["start"] = ip_address
provider_data["discovery_range"]["end"] = ip_address
host_provider = VMwareProvider(
name=host["name"],
hostname=host["name"],
ip_address=ip_address,
credentials={'default': cred},
provider_data=provider_data,
)
argvalues[i].append(host_provider)
idlist[i] = "{}/{}".format(args['provider'].key, host["name"])
new_idlist.append(idlist[i])
new_argvalues.append(argvalues[i])
testgen.parametrize(metafunc, argnames, new_argvalues, ids=new_idlist, scope="module")
示例14: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.infra_providers(metafunc,
required_fields=[
['provisioning', 'template'],
['provisioning', 'host'],
['provisioning', 'datastore']
])
testgen.parametrize(metafunc, argnames, argvalues, ids=idlist, scope="module")
示例15: pytest_generate_tests
def pytest_generate_tests(metafunc):
# Filter out providers without provisioning data or hosts defined
argnames, argvalues, idlist = testgen.provider_by_type(metafunc, ['rhevm'],
required_fields=[
['provisioning', 'ci-template'],
['provisioning', 'ci-username'],
['provisioning', 'ci-pass'],
['provisioning', 'image']
])
testgen.parametrize(metafunc, argnames, argvalues, ids=idlist, scope="module")