Skip to content

Commit 41e66de

Browse files
glehmannydirson
authored andcommitted
fix typehints in install tests
note that `with_args` is used as a workaround for a pytest type-hint bug that declares the function passed to a marker as returned by the marker, which is not true with a lambda. Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent 762859d commit 41e66de

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

tests/install/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
from typing import Sequence
34
import pytest
45
import pytest_dependency # type: ignore
56
import tempfile
@@ -322,6 +323,7 @@ def xcpng_chained(request):
322323
marker = request.node.get_closest_marker("continuation_of")
323324
assert marker is not None, "xcpng_chained fixture requires 'continuation_of' marker"
324325
continuation_of = callable_marker(marker.args[0], request)
326+
assert isinstance(continuation_of, Sequence)
325327

326328
vm_defs = [dict(name=vm_spec['vm'],
327329
image_test=vm_spec['image_test'],

tests/install/test.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class TestNested:
7878
cd_vbd=dict(device="xvdd", userdevice="3"),
7979
vifs=[dict(index=0, network_name=NETWORKS["MGMT"])],
8080
))
81-
@pytest.mark.answerfile(
81+
@pytest.mark.answerfile.with_args(
8282
lambda system_disks_names, local_sr, package_source, iso_version: AnswerFile("INSTALL")
8383
.top_setattr({} if local_sr == "nosr" else {"sr-type": local_sr})
8484
.top_append(
@@ -111,7 +111,7 @@ def test_install(self, vm_booted_with_installer, system_disks_names,
111111
"xs70",
112112
))
113113
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
114-
@pytest.mark.continuation_of(
114+
@pytest.mark.continuation_of.with_args(
115115
lambda version, firmware, local_sr, package_source: [dict(
116116
vm="vm1",
117117
image_test=f"TestNested::test_install[{firmware}-{version}-{package_source}-{local_sr}]")])
@@ -245,6 +245,7 @@ def _test_firstboot(self, create_vms, mode, *, machine='DEFAULT', is_restore=Fal
245245
raise AssertionError(f"Unhandled LSB release {lsb_rel!r}")
246246
# check for firstboot issues
247247
# FIXME: flaky, must check logs extraction on failure
248+
stamp = ''
248249
try:
249250
for stamp in sorted(STAMPS):
250251
wait_for(lambda: pool.master.ssh(["test", "-e", f"{STAMPS_DIR}/{stamp}"],
@@ -302,7 +303,7 @@ def _test_firstboot(self, create_vms, mode, *, machine='DEFAULT', is_restore=Fal
302303
"xs70",
303304
))
304305
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
305-
@pytest.mark.continuation_of(
306+
@pytest.mark.continuation_of.with_args(
306307
lambda firmware, version, machine, local_sr, package_source: [
307308
dict(vm="vm1",
308309
image_test=("TestNested::test_tune_firstboot"
@@ -329,11 +330,11 @@ def test_boot_inst(self, create_vms,
329330
("821.1", "821.1"),
330331
])
331332
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
332-
@pytest.mark.continuation_of(
333+
@pytest.mark.continuation_of.with_args(
333334
lambda firmware, orig_version, machine, package_source, local_sr: [dict(
334335
vm="vm1",
335336
image_test=f"TestNested::test_boot_inst[{firmware}-{orig_version}-{machine}-{package_source}-{local_sr}]")])
336-
@pytest.mark.answerfile(
337+
@pytest.mark.answerfile.with_args(
337338
lambda system_disks_names, package_source, iso_version: AnswerFile("UPGRADE").top_append(
338339
{"iso": {"TAG": "source", "type": "local"},
339340
"net": {"TAG": "source", "type": "url",
@@ -365,7 +366,7 @@ def test_upgrade(self, vm_booted_with_installer, system_disks_names,
365366
"821.1-821.1",
366367
))
367368
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
368-
@pytest.mark.continuation_of(
369+
@pytest.mark.continuation_of.with_args(
369370
lambda firmware, mode, machine, package_source, local_sr: [dict(
370371
vm="vm1",
371372
image_test=(f"TestNested::test_upgrade[{firmware}-{mode}-{machine}-{package_source}-{local_sr}]"))])
@@ -390,7 +391,7 @@ def test_boot_upg(self, create_vms,
390391
("821.1-821.1", "821.1"),
391392
])
392393
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
393-
@pytest.mark.continuation_of(
394+
@pytest.mark.continuation_of.with_args(
394395
lambda firmware, orig_version, local_sr, package_source: [dict(
395396
vm="vm1",
396397
image_test=f"TestNested::test_boot_upg[{firmware}-{orig_version}-host1-{package_source}-{local_sr}]")])
@@ -421,7 +422,7 @@ def test_restore(self, vm_booted_with_installer, system_disks_names,
421422
"821.1-821.1-821.1",
422423
))
423424
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
424-
@pytest.mark.continuation_of(
425+
@pytest.mark.continuation_of.with_args(
425426
lambda firmware, mode, package_source, local_sr: [dict(
426427
vm="vm1",
427428
image_test=(f"TestNested::test_restore[{firmware}-{mode}-{package_source}-{local_sr}]"))])

tests/install/test_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# test the answerfile fixture can run on 2 parametrized instances
77
# of the test in one run
8-
@pytest.mark.answerfile(lambda: AnswerFile("INSTALL").top_append(
8+
@pytest.mark.answerfile.with_args(lambda: AnswerFile("INSTALL").top_append(
99
{"TAG": "source", "type": "local"},
1010
{"TAG": "primary-disk", "CONTENTS": "nvme0n1"},
1111
))

0 commit comments

Comments
 (0)