Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,26 @@ def pytest_collection_modifyitems(items: list[pytest.Item], config: pytest.Confi
# Automatically mark tests based on fixtures they require.
# Check pytest.ini or pytest --markers for marker descriptions.

markable_fixtures = [
'uefi_vm',
'unix_vm',
'windows_vm',
'hostA2',
'hostB1',
'unused_512B_disks',
'unused_4k_disks',
]
# Maps fixture name -> mark name. skip_if_not_* variants map to the same mark as their
# fail counterparts since they still require the same VM type.
markable_fixtures: dict[str, str] = {
'uefi_vm': 'uefi_vm',
'skip_if_not_uefi_vm': 'uefi_vm',
'unix_vm': 'unix_vm',
'skip_if_not_unix_vm': 'unix_vm',
'windows_vm': 'windows_vm',
'skip_if_not_windows_vm': 'windows_vm',
'hostA2': 'hostA2',
'hostB1': 'hostB1',
'unused_512B_disks': 'unused_512B_disks',
'unused_4k_disks': 'unused_4k_disks',
}

for item in items:
fixturenames = getattr(item, 'fixturenames', ())
for fixturename in markable_fixtures:
for fixturename, markname in markable_fixtures.items():
if fixturename in fixturenames:
item.add_marker(fixturename)
item.add_marker(markname)

if 'vm_ref' not in fixturenames:
item.add_marker('no_vm')
Expand Down Expand Up @@ -752,7 +757,16 @@ def running_vm(started_vm: VM) -> VM:
def unix_vm(imported_vm: VM) -> Generator[VM, None, None]:
vm = imported_vm
if vm.is_windows:
pytest.skip("This test is only compatible with unix VMs.")
pytest.fail("This test requires a unix VM.")
yield vm

@pytest.fixture(scope='module')
def skip_if_not_unix_vm(imported_vm: VM) -> Generator[VM, None, None]:
# Skip (not fail) is intentional: used in multi-VM jobs where both unix and Windows VMs
# are present by design. A non-matching VM is expected, not a misconfiguration.
vm = imported_vm
if vm.is_windows:
pytest.skip("Skipping: this test is only compatible with unix VMs.")
yield vm

@pytest.fixture(scope="module")
Expand All @@ -764,14 +778,32 @@ def running_unix_vm(unix_vm: VM, running_vm: VM) -> VM:
def windows_vm(imported_vm: VM) -> Generator[VM, None, None]:
vm = imported_vm
if not vm.is_windows:
pytest.skip("This test is only compatible with Windows VMs.")
pytest.fail("This test requires a Windows VM.")
yield vm

@pytest.fixture(scope='module')
def skip_if_not_windows_vm(imported_vm: VM) -> Generator[VM, None, None]:
# Skip (not fail) is intentional: used in multi-VM jobs where both unix and Windows VMs
# are present by design. A non-matching VM is expected, not a misconfiguration.
vm = imported_vm
if not vm.is_windows:
pytest.skip("Skipping: this test is only compatible with Windows VMs.")
yield vm

@pytest.fixture(scope='module')
def uefi_vm(imported_vm: VM) -> Generator[VM, None, None]:
vm = imported_vm
if not vm.is_uefi:
pytest.skip('This test requires an UEFI VM')
pytest.fail('This test requires a UEFI VM.')
yield vm

@pytest.fixture(scope='module')
def skip_if_not_uefi_vm(imported_vm: VM) -> Generator[VM, None, None]:
# Skip (not fail) is intentional: used in multi-VM jobs where both UEFI and non-UEFI VMs
# are present by design. A non-matching VM is expected, not a misconfiguration.
vm = imported_vm
if not vm.is_uefi:
pytest.skip('Skipping: this test requires a UEFI VM.')
yield vm

@pytest.fixture(scope='session')
Expand Down
2 changes: 1 addition & 1 deletion tests/guest_tools/unix/test_guest_tools_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self) -> None:


@pytest.mark.multi_vms
@pytest.mark.usefixtures("unix_vm")
@pytest.mark.usefixtures("skip_if_not_unix_vm")
class TestGuestToolsUnix:
@pytest.fixture(scope='class')
def state(self) -> State:
Expand Down
6 changes: 3 additions & 3 deletions tests/guest_tools/win/test_guest_tools_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@


@pytest.mark.multi_vms
@pytest.mark.usefixtures("windows_vm")
@pytest.mark.usefixtures("skip_if_not_windows_vm")
class TestGuestToolsWindows:
def test_drivers_detected(self, vm_install_test_tools_per_test_class: VM) -> None:
pass
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_xenvbd_ssd(self, vm_install_test_tools_per_test_class: VM) -> None:


@pytest.mark.multi_vms
@pytest.mark.usefixtures("windows_vm")
@pytest.mark.usefixtures("skip_if_not_windows_vm")
class TestGuestToolsWindowsDestructive:
def test_uninstall_tools(self, vm_install_test_tools_no_reboot: VM) -> None:
vm = vm_install_test_tools_no_reboot
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_install_with_other_tools(
exitcode = install_guest_tools(vm, guest_tools_iso, PowerAction.Nothing, check=False)
assert exitcode == ERROR_INSTALL_FAILURE

@pytest.mark.usefixtures("uefi_vm")
@pytest.mark.usefixtures("skip_if_not_uefi_vm")
def test_uefi_vm_suspend_refused_without_tools(self, running_unsealed_windows_vm: VM) -> None:
vm = running_unsealed_windows_vm
with pytest.raises(SSHCommandFailed, match="lacks the feature"):
Expand Down
2 changes: 1 addition & 1 deletion tests/guest_tools/win/test_xenclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def onboarding_guest_tools_iso(guest_tools_iso: Dict[str, Any]) -> Dict[str, Any


@pytest.mark.multi_vms
@pytest.mark.usefixtures("windows_vm")
@pytest.mark.usefixtures("skip_if_not_windows_vm")
class TestXenClean:
def test_xenclean_without_tools(
self, running_unsealed_windows_vm: VM, guest_tools_iso: Dict[str, Any]
Expand Down
4 changes: 2 additions & 2 deletions tests/uefi_sb/test_uefistored_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

@pytest.mark.small_vm
@pytest.mark.usefixtures("host_less_than_8_3")
@pytest.mark.usefixtures("pool_without_uefi_certs", "unix_vm")
@pytest.mark.usefixtures("pool_without_uefi_certs", "skip_if_not_unix_vm")
class TestGuestLinuxUEFISecureBoot:
PK: EFIAuth
KEK: EFIAuth
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_sb_off_really_means_off(self, uefi_vm: VM) -> None:


@pytest.mark.usefixtures("host_less_than_8_3")
@pytest.mark.usefixtures("pool_without_uefi_certs", "windows_vm")
@pytest.mark.usefixtures("pool_without_uefi_certs", "skip_if_not_windows_vm")
class TestGuestWindowsUEFISecureBoot:
@pytest.fixture(autouse=True)
def setup_and_cleanup(self, uefi_vm_and_snapshot: tuple[VM, Snapshot]) -> Generator[None, None, None]:
Expand Down
4 changes: 2 additions & 2 deletions tests/uefi_sb/test_varstored_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

@pytest.mark.small_vm
@pytest.mark.usefixtures("host_at_least_8_3")
@pytest.mark.usefixtures("unix_vm")
@pytest.mark.usefixtures("skip_if_not_unix_vm")
class TestGuestLinuxUEFISecureBoot:
PK: EFIAuth
KEK: EFIAuth
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_append_with_poison(self, uefi_vm: VM) -> None:


@pytest.mark.usefixtures("host_at_least_8_3")
@pytest.mark.usefixtures("windows_vm")
@pytest.mark.usefixtures("skip_if_not_windows_vm")
class TestGuestWindowsUEFISecureBoot:
@pytest.fixture(autouse=True)
def setup_and_cleanup(self, uefi_vm_and_snapshot: tuple[VM, Snapshot]) -> Generator[None, None, None]:
Expand Down
Loading