Skip to content

Commit aec5c3d

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 aec5c3d

7 files changed

Lines changed: 46 additions & 16 deletions

File tree

conftest.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ def pytest_collection_modifyitems(items: list[pytest.Item], config: pytest.Confi
172172

173173
markable_fixtures = [
174174
'uefi_vm',
175+
'skip_if_not_uefi_vm',
175176
'unix_vm',
177+
'skip_if_not_unix_vm',
176178
'windows_vm',
179+
'skip_if_not_windows_vm',
177180
'hostA2',
178181
'hostB1',
179182
'unused_512B_disks',
@@ -752,7 +755,16 @@ def running_vm(started_vm: VM) -> VM:
752755
def unix_vm(imported_vm: VM) -> Generator[VM, None, None]:
753756
vm = imported_vm
754757
if vm.is_windows:
755-
pytest.skip("This test is only compatible with unix VMs.")
758+
pytest.fail("This test requires a unix VM.")
759+
yield vm
760+
761+
@pytest.fixture(scope='module')
762+
def skip_if_not_unix_vm(imported_vm: VM) -> Generator[VM, None, None]:
763+
# Skip (not fail) is intentional: used in multi-VM jobs where both unix and Windows VMs
764+
# are present by design. A non-matching VM is expected, not a misconfiguration.
765+
vm = imported_vm
766+
if vm.is_windows:
767+
pytest.skip("Skipping: this test is only compatible with unix VMs.")
756768
yield vm
757769

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

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

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

jobs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class JobData(TypedDict):
385385
"tests/uefi_sb/test_varstored_sb.py",
386386
"tests/uefi_sb/test_sb_state.py"
387387
],
388-
"markers": "not windows_vm",
388+
"markers": "not windows_vm and not skip_if_not_windows_vm",
389389
},
390390
"sb-certificates": {
391391
"description": "tests certificate propagation to disk by XAPI, and to VMs by uefistored/varstored",
@@ -414,7 +414,7 @@ class JobData(TypedDict):
414414
"--vm": "single/small_vm_windows",
415415
},
416416
"paths": ["tests/uefi_sb"],
417-
"markers": "windows_vm",
417+
"markers": "windows_vm or skip_if_not_windows_vm",
418418
},
419419
"sb-unix-multi": {
420420
"description": "checks basic Secure-Boot support on a variety of Unix VMs",
@@ -428,7 +428,7 @@ class JobData(TypedDict):
428428
"--vm[]": "multi/uefi_unix",
429429
},
430430
"paths": ["tests/uefi_sb"],
431-
"markers": "multi_vms and unix_vm",
431+
"markers": "multi_vms and skip_if_not_unix_vm",
432432
},
433433
"sb-windows-multi": {
434434
"description": "checks basic Secure-Boot support on a variety of Windows VMs",
@@ -441,7 +441,7 @@ class JobData(TypedDict):
441441
"--vm[]": "multi/uefi_windows",
442442
},
443443
"paths": ["tests/uefi_sb"],
444-
"markers": "multi_vms and windows_vm",
444+
"markers": "multi_vms and skip_if_not_windows_vm",
445445
},
446446
"tools-unix": {
447447
"description": "tests our unix guest tools on a single small VM",

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)