Skip to content

Commit 6c40003

Browse files
committed
conftest: split vm-type fixtures into require and skip variants
unix_vm, windows_vm, and uefi_vm now call pytest.fail() if the VM is the wrong type, matching the expectation that these fixtures enforce a requirement. The new skip_if_not_unix_vm, skip_if_not_windows_vm, and skip_if_not_uefi_vm fixtures call pytest.skip() instead, for use in multi-VM jobs where different VMs types are expected and non-matching ones should be silently skipped rather than failed. So, updated all multi_vms-annotated classes to use the skip variants. The markable_fixtures list and jobs.py marker expressions are updated accordingly. Signed-off-by: Julian Vetter <julian.vetter@vates.tech>
1 parent f7467dd commit 6c40003

6 files changed

Lines changed: 55 additions & 23 deletions

File tree

conftest.py

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,26 @@ def pytest_collection_modifyitems(items: list[pytest.Item], config: pytest.Confi
170170
# Automatically mark tests based on fixtures they require.
171171
# Check pytest.ini or pytest --markers for marker descriptions.
172172

173-
markable_fixtures = [
174-
'uefi_vm',
175-
'unix_vm',
176-
'windows_vm',
177-
'hostA2',
178-
'hostB1',
179-
'unused_512B_disks',
180-
'unused_4k_disks',
181-
]
173+
# Maps fixture name -> mark name. skip_if_not_* variants map to the same mark as their
174+
# fail counterparts since they still require the same VM type.
175+
markable_fixtures: dict[str, str] = {
176+
'uefi_vm': 'uefi_vm',
177+
'skip_if_not_uefi_vm': 'uefi_vm',
178+
'unix_vm': 'unix_vm',
179+
'skip_if_not_unix_vm': 'unix_vm',
180+
'windows_vm': 'windows_vm',
181+
'skip_if_not_windows_vm': 'windows_vm',
182+
'hostA2': 'hostA2',
183+
'hostB1': 'hostB1',
184+
'unused_512B_disks': 'unused_512B_disks',
185+
'unused_4k_disks': 'unused_4k_disks',
186+
}
182187

183188
for item in items:
184189
fixturenames = getattr(item, 'fixturenames', ())
185-
for fixturename in markable_fixtures:
190+
for fixturename, markname in markable_fixtures.items():
186191
if fixturename in fixturenames:
187-
item.add_marker(fixturename)
192+
item.add_marker(markname)
188193

189194
if 'vm_ref' not in fixturenames:
190195
item.add_marker('no_vm')
@@ -752,7 +757,16 @@ def running_vm(started_vm: VM) -> VM:
752757
def unix_vm(imported_vm: VM) -> Generator[VM, None, None]:
753758
vm = imported_vm
754759
if vm.is_windows:
755-
pytest.skip("This test is only compatible with unix VMs.")
760+
pytest.fail("This test requires a unix VM.")
761+
yield vm
762+
763+
@pytest.fixture(scope='module')
764+
def skip_if_not_unix_vm(imported_vm: VM) -> Generator[VM, None, None]:
765+
# Skip (not fail) is intentional: used in multi-VM jobs where both unix and Windows VMs
766+
# are present by design. A non-matching VM is expected, not a misconfiguration.
767+
vm = imported_vm
768+
if vm.is_windows:
769+
pytest.skip("Skipping: this test is only compatible with unix VMs.")
756770
yield vm
757771

758772
@pytest.fixture(scope="module")
@@ -764,14 +778,32 @@ def running_unix_vm(unix_vm: VM, running_vm: VM) -> VM:
764778
def windows_vm(imported_vm: VM) -> Generator[VM, None, None]:
765779
vm = imported_vm
766780
if not vm.is_windows:
767-
pytest.skip("This test is only compatible with Windows VMs.")
781+
pytest.fail("This test requires a Windows VM.")
782+
yield vm
783+
784+
@pytest.fixture(scope='module')
785+
def skip_if_not_windows_vm(imported_vm: VM) -> Generator[VM, None, None]:
786+
# Skip (not fail) is intentional: used in multi-VM jobs where both unix and Windows VMs
787+
# are present by design. A non-matching VM is expected, not a misconfiguration.
788+
vm = imported_vm
789+
if not vm.is_windows:
790+
pytest.skip("Skipping: this test is only compatible with Windows VMs.")
768791
yield vm
769792

770793
@pytest.fixture(scope='module')
771794
def uefi_vm(imported_vm: VM) -> Generator[VM, None, None]:
772795
vm = imported_vm
773796
if not vm.is_uefi:
774-
pytest.skip('This test requires an UEFI VM')
797+
pytest.fail('This test requires a UEFI VM.')
798+
yield vm
799+
800+
@pytest.fixture(scope='module')
801+
def skip_if_not_uefi_vm(imported_vm: VM) -> Generator[VM, None, None]:
802+
# Skip (not fail) is intentional: used in multi-VM jobs where both UEFI and non-UEFI VMs
803+
# are present by design. A non-matching VM is expected, not a misconfiguration.
804+
vm = imported_vm
805+
if not vm.is_uefi:
806+
pytest.skip('Skipping: this test requires a UEFI VM.')
775807
yield vm
776808

777809
@pytest.fixture(scope='session')

tests/guest_tools/unix/test_guest_tools_unix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self) -> None:
2626

2727

2828
@pytest.mark.multi_vms
29-
@pytest.mark.usefixtures("unix_vm")
29+
@pytest.mark.usefixtures("skip_if_not_unix_vm")
3030
class TestGuestToolsUnix:
3131
@pytest.fixture(scope='class')
3232
def state(self) -> State:

tests/guest_tools/win/test_guest_tools_win.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171

7272
@pytest.mark.multi_vms
73-
@pytest.mark.usefixtures("windows_vm")
73+
@pytest.mark.usefixtures("skip_if_not_windows_vm")
7474
class TestGuestToolsWindows:
7575
def test_drivers_detected(self, vm_install_test_tools_per_test_class: VM) -> None:
7676
pass
@@ -144,7 +144,7 @@ def test_xenvbd_ssd(self, vm_install_test_tools_per_test_class: VM) -> None:
144144

145145

146146
@pytest.mark.multi_vms
147-
@pytest.mark.usefixtures("windows_vm")
147+
@pytest.mark.usefixtures("skip_if_not_windows_vm")
148148
class TestGuestToolsWindowsDestructive:
149149
def test_uninstall_tools(self, vm_install_test_tools_no_reboot: VM) -> None:
150150
vm = vm_install_test_tools_no_reboot
@@ -176,7 +176,7 @@ def test_install_with_other_tools(
176176
exitcode = install_guest_tools(vm, guest_tools_iso, PowerAction.Nothing, check=False)
177177
assert exitcode == ERROR_INSTALL_FAILURE
178178

179-
@pytest.mark.usefixtures("uefi_vm")
179+
@pytest.mark.usefixtures("skip_if_not_uefi_vm")
180180
def test_uefi_vm_suspend_refused_without_tools(self, running_unsealed_windows_vm: VM) -> None:
181181
vm = running_unsealed_windows_vm
182182
with pytest.raises(SSHCommandFailed, match="lacks the feature"):

tests/guest_tools/win/test_xenclean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def onboarding_guest_tools_iso(guest_tools_iso: Dict[str, Any]) -> Dict[str, Any
9494

9595

9696
@pytest.mark.multi_vms
97-
@pytest.mark.usefixtures("windows_vm")
97+
@pytest.mark.usefixtures("skip_if_not_windows_vm")
9898
class TestXenClean:
9999
def test_xenclean_without_tools(
100100
self, running_unsealed_windows_vm: VM, guest_tools_iso: Dict[str, Any]

tests/uefi_sb/test_uefistored_sb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
@pytest.mark.small_vm
4040
@pytest.mark.usefixtures("host_less_than_8_3")
41-
@pytest.mark.usefixtures("pool_without_uefi_certs", "unix_vm")
41+
@pytest.mark.usefixtures("pool_without_uefi_certs", "skip_if_not_unix_vm")
4242
class TestGuestLinuxUEFISecureBoot:
4343
PK: EFIAuth
4444
KEK: EFIAuth
@@ -135,7 +135,7 @@ def test_sb_off_really_means_off(self, uefi_vm: VM) -> None:
135135

136136

137137
@pytest.mark.usefixtures("host_less_than_8_3")
138-
@pytest.mark.usefixtures("pool_without_uefi_certs", "windows_vm")
138+
@pytest.mark.usefixtures("pool_without_uefi_certs", "skip_if_not_windows_vm")
139139
class TestGuestWindowsUEFISecureBoot:
140140
@pytest.fixture(autouse=True)
141141
def setup_and_cleanup(self, uefi_vm_and_snapshot: tuple[VM, Snapshot]) -> Generator[None, None, None]:

tests/uefi_sb/test_varstored_sb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
@pytest.mark.small_vm
3939
@pytest.mark.usefixtures("host_at_least_8_3")
40-
@pytest.mark.usefixtures("unix_vm")
40+
@pytest.mark.usefixtures("skip_if_not_unix_vm")
4141
class TestGuestLinuxUEFISecureBoot:
4242
PK: EFIAuth
4343
KEK: EFIAuth
@@ -137,7 +137,7 @@ def test_append_with_poison(self, uefi_vm: VM) -> None:
137137

138138

139139
@pytest.mark.usefixtures("host_at_least_8_3")
140-
@pytest.mark.usefixtures("windows_vm")
140+
@pytest.mark.usefixtures("skip_if_not_windows_vm")
141141
class TestGuestWindowsUEFISecureBoot:
142142
@pytest.fixture(autouse=True)
143143
def setup_and_cleanup(self, uefi_vm_and_snapshot: tuple[VM, Snapshot]) -> Generator[None, None, None]:

0 commit comments

Comments
 (0)