Skip to content

Commit bae505b

Browse files
committed
conftest: stop using a test parameter for hosts
Hosts can also now be specified also using severeal args, like `--hosts A,B --hosts C` Signed-off-by: Yann Dirson <[email protected]>
1 parent 7d985ed commit bae505b

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

conftest.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import logging
23
import pytest
34
import tempfile
@@ -103,10 +104,14 @@ def setup_host(hostname_or_ip):
103104
return h
104105

105106
@pytest.fixture(scope='session')
106-
def hosts(request):
107+
def hosts(pytestconfig):
107108
# a list of master hosts, each from a different pool
108-
hostname_list = request.param.split(',')
109+
hosts_args = pytestconfig.getoption("hosts")
110+
hosts_split = [hostlist.split(',') for hostlist in hosts_args]
111+
hostname_list = list(itertools.chain(*hosts_split))
109112
host_list = [setup_host(hostname_or_ip) for hostname_or_ip in hostname_list]
113+
if not host_list:
114+
pytest.fail("This test requires at least one --hosts parameter")
110115
yield host_list
111116

112117
@pytest.fixture(scope='session')
@@ -430,8 +435,6 @@ def second_network(request, host):
430435
return network_uuid
431436

432437
def pytest_generate_tests(metafunc):
433-
if "hosts" in metafunc.fixturenames:
434-
metafunc.parametrize("hosts", metafunc.config.getoption("hosts"), indirect=True, scope="session")
435438
if "vm_ref" in metafunc.fixturenames:
436439
vms = metafunc.config.getoption("vm")
437440
if not vms:

tests/storage/nfs/test_nfs_sr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_create_and_destroy_sr(self, host, dispatch_nfs):
2020
sr.destroy(verify=True)
2121

2222
# Make sure these fixtures are called before the parametrized one
23-
@pytest.mark.usefixtures('sr_device_config', 'hosts')
23+
@pytest.mark.usefixtures('sr_device_config')
2424
class TestNFSSR:
2525
@pytest.mark.quicktest
2626
@pytest.mark.parametrize('dispatch_nfs', ['nfs_sr', 'nfs4_sr'], indirect=True)

tests/storage/nfs/test_nfs_sr_crosspool_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@pytest.mark.big_vm # and ideally with a big VM to test it scales
1313
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
1414
# Make sure these fixtures are called before the parametrized one
15-
@pytest.mark.usefixtures('sr_device_config', 'vm_ref', 'hosts')
15+
@pytest.mark.usefixtures('sr_device_config', 'vm_ref')
1616
class Test:
1717
@pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True)
1818
def test_cold_crosspool_migration(self, host, hostB1, dispatch_nfs, local_sr_on_hostB1):

tests/storage/nfs/test_nfs_sr_intrapool_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@pytest.mark.big_vm # and ideally with a big VM to test it scales
1313
@pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2")
1414
# Make sure these fixtures are called before the parametrized one
15-
@pytest.mark.usefixtures('sr_device_config', 'vm_ref', 'hosts')
15+
@pytest.mark.usefixtures('sr_device_config', 'vm_ref')
1616
class Test:
1717
@pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True)
1818
def test_live_intrapool_shared_migration(self, host, hostA2, dispatch_nfs):

0 commit comments

Comments
 (0)