|
19 | 19 | # need to import them in the global conftest.py so that they are recognized as fixtures.
|
20 | 20 | from pkgfixtures import formatted_and_mounted_ext4_disk, sr_disk_wiped
|
21 | 21 |
|
| 22 | +### pytest hooks |
| 23 | + |
22 | 24 | def pytest_addoption(parser):
|
23 | 25 | parser.addoption(
|
24 | 26 | "--hosts",
|
@@ -70,6 +72,42 @@ def pytest_configure(config):
|
70 | 72 | global_config.ignore_ssh_banner = config.getoption('--ignore-ssh-banner')
|
71 | 73 | global_config.ssh_output_max_lines = int(config.getoption('--ssh-output-max-lines'))
|
72 | 74 |
|
| 75 | +def pytest_generate_tests(metafunc): |
| 76 | + if "vm_ref" in metafunc.fixturenames: |
| 77 | + vms = metafunc.config.getoption("vm") |
| 78 | + if not vms: |
| 79 | + vms = [None] # no --vm parameter does not mean skip the test, for us, it means use the default |
| 80 | + metafunc.parametrize("vm_ref", vms, indirect=True, scope="module") |
| 81 | + |
| 82 | +def pytest_collection_modifyitems(items, config): |
| 83 | + # Automatically mark tests based on fixtures they require. |
| 84 | + # Check pytest.ini or pytest --markers for marker descriptions. |
| 85 | + |
| 86 | + markable_fixtures = [ |
| 87 | + 'uefi_vm', |
| 88 | + 'unix_vm', |
| 89 | + 'windows_vm', |
| 90 | + 'hostA2', |
| 91 | + 'hostB1', |
| 92 | + 'sr_disk', |
| 93 | + 'sr_disk_4k' |
| 94 | + ] |
| 95 | + |
| 96 | + for item in items: |
| 97 | + fixturenames = getattr(item, 'fixturenames', ()) |
| 98 | + for fixturename in markable_fixtures: |
| 99 | + if fixturename in fixturenames: |
| 100 | + item.add_marker(fixturename) |
| 101 | + |
| 102 | + if 'vm_ref' not in fixturenames: |
| 103 | + item.add_marker('no_vm') |
| 104 | + |
| 105 | + if item.get_closest_marker('multi_vms'): |
| 106 | + # multi_vms implies small_vm |
| 107 | + item.add_marker('small_vm') |
| 108 | + |
| 109 | +### fixtures |
| 110 | + |
73 | 111 | def setup_host(hostname_or_ip):
|
74 | 112 | pool = Pool(hostname_or_ip)
|
75 | 113 | h = pool.master
|
@@ -400,37 +438,3 @@ def second_network(pytestconfig, host):
|
400 | 438 | if network_uuid == host.management_network():
|
401 | 439 | pytest.fail("--second-network must NOT be the management network")
|
402 | 440 | return network_uuid
|
403 |
| - |
404 |
| -def pytest_generate_tests(metafunc): |
405 |
| - if "vm_ref" in metafunc.fixturenames: |
406 |
| - vms = metafunc.config.getoption("vm") |
407 |
| - if not vms: |
408 |
| - vms = [None] # no --vm parameter does not mean skip the test, for us, it means use the default |
409 |
| - metafunc.parametrize("vm_ref", vms, indirect=True, scope="module") |
410 |
| - |
411 |
| -def pytest_collection_modifyitems(items, config): |
412 |
| - # Automatically mark tests based on fixtures they require. |
413 |
| - # Check pytest.ini or pytest --markers for marker descriptions. |
414 |
| - |
415 |
| - markable_fixtures = [ |
416 |
| - 'uefi_vm', |
417 |
| - 'unix_vm', |
418 |
| - 'windows_vm', |
419 |
| - 'hostA2', |
420 |
| - 'hostB1', |
421 |
| - 'sr_disk', |
422 |
| - 'sr_disk_4k' |
423 |
| - ] |
424 |
| - |
425 |
| - for item in items: |
426 |
| - fixturenames = getattr(item, 'fixturenames', ()) |
427 |
| - for fixturename in markable_fixtures: |
428 |
| - if fixturename in fixturenames: |
429 |
| - item.add_marker(fixturename) |
430 |
| - |
431 |
| - if 'vm_ref' not in fixturenames: |
432 |
| - item.add_marker('no_vm') |
433 |
| - |
434 |
| - if item.get_closest_marker('multi_vms'): |
435 |
| - # multi_vms implies small_vm |
436 |
| - item.add_marker('small_vm') |
|
0 commit comments