Skip to content

Commit d3278dd

Browse files
committed
Add explicit enable switch for reboot/flaky markers
This avoids us having to specify 'not reboot/flaky' everywhere in jobs.py by adding an implicit skip marker if the corresponding arguments are not specified in the pytest call. Signed-off-by: Tu Dinh <ngoc-tu.dinh@vates.tech>
1 parent 3e14afe commit d3278dd

2 files changed

Lines changed: 38 additions & 9 deletions

File tree

conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
prefix_object_name,
2121
setup_formatted_and_mounted_disk,
2222
shortened_nodeid,
23+
strtobool,
2324
teardown_formatted_and_mounted_disk,
2425
vm_image,
2526
wait_for,
@@ -47,6 +48,8 @@
4748

4849
# pytest hooks
4950

51+
NONDEFAULT_MARKERS = ["reboot", "flaky"]
52+
5053
def pytest_addoption(parser: pytest.Parser):
5154
parser.addoption(
5255
"--nest",
@@ -99,6 +102,13 @@ def pytest_addoption(parser: pytest.Parser):
99102
help="Format of VDI to execute tests on."
100103
"Example: vhd,qcow2"
101104
)
105+
# Markers
106+
for marker in NONDEFAULT_MARKERS:
107+
parser.addoption(
108+
f"--enable-{marker}",
109+
type=strtobool,
110+
help=f"Enable tests with the {marker} marker"
111+
)
102112

103113
def pytest_configure(config: pytest.Config):
104114
global_config.ignore_ssh_banner = config.getoption('--ignore-ssh-banner')
@@ -144,6 +154,15 @@ def pytest_collection_modifyitems(items: List[pytest.Item], config: pytest.Confi
144154
# multi_vms implies small_vm
145155
item.add_marker('small_vm')
146156

157+
# Disable marked tests if --enable-marker=true is not provided
158+
for marker in NONDEFAULT_MARKERS:
159+
if not config.getoption(f"--enable-{marker}"):
160+
skip = pytest.mark.skip(reason="test disabled, pass `--enable-{marker}=true` to enable")
161+
for item in items:
162+
if marker in item.keywords:
163+
item.add_marker(skip)
164+
165+
147166
# BEGIN make test results visible from fixtures
148167
# from https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures
149168

jobs.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"tests/xapi_plugins",
3333
"tests/install/test_fixtures.py",
3434
],
35-
"markers": "(small_vm or no_vm) and not flaky and not reboot and not complex_prerequisites",
35+
"markers": "(small_vm or no_vm) and not complex_prerequisites",
3636
},
3737
"main-multi-unix": {
3838
"description": "a group of tests that need to run on the largest variety of VMs - unix split",
@@ -47,7 +47,7 @@
4747
"--vm[]": "multi/all_unix",
4848
},
4949
"paths": ["tests/misc", "tests/migration"],
50-
"markers": "multi_vms and not flaky and not reboot",
50+
"markers": "multi_vms"
5151
},
5252
"main-multi-windows": {
5353
"description": "a group of tests that need to run on the largest variety of VMs - windows split",
@@ -62,7 +62,7 @@
6262
"--vm[]": "multi/all_windows",
6363
},
6464
"paths": ["tests/misc", "tests/migration"],
65-
"markers": "multi_vms and not flaky and not reboot",
65+
"markers": "multi_vms"
6666
},
6767
"packages": {
6868
"description": "tests that packages can be installed correctly",
@@ -87,7 +87,7 @@
8787
"--vm": "single/small_vm",
8888
},
8989
"paths": ["tests/storage"],
90-
"markers": "(small_vm or no_vm) and not reboot and not quicktest and not unused_4k_disks",
90+
"markers": "(small_vm or no_vm) and not quicktest and not unused_4k_disks",
9191
"name_filter": "not migration and not linstor",
9292
},
9393
"storage-migrations": {
@@ -117,10 +117,11 @@
117117
],
118118
"nb_pools": 1,
119119
"params": {
120+
"--enable-reboot": True,
120121
"--vm": "single/small_vm",
121122
},
122123
"paths": ["tests/storage"],
123-
"markers": "reboot and not flaky and not unused_4k_disks",
124+
"markers": "reboot and not unused_4k_disks",
124125
"name_filter": "not linstor",
125126
},
126127
"storage-quicktest": {
@@ -149,7 +150,7 @@
149150
"--vm": "single/small_vm",
150151
},
151152
"paths": ["tests/storage/linstor"],
152-
"markers": "(small_vm or no_vm) and not reboot and not quicktest",
153+
"markers": "(small_vm or no_vm) and not quicktest",
153154
"name_filter": "not migration",
154155
},
155156
"linstor-migrations": {
@@ -177,6 +178,7 @@
177178
],
178179
"nb_pools": 1,
179180
"params": {
181+
"--enable-reboot": True,
180182
"--vm": "single/small_vm",
181183
},
182184
"paths": ["tests/storage/linstor"],
@@ -206,7 +208,7 @@
206208
"--vm": "single/small_vm",
207209
},
208210
"paths": ["tests/storage"],
209-
"markers": "(small_vm or no_vm) and unused_4k_disks and not reboot and not quicktest",
211+
"markers": "(small_vm or no_vm) and unused_4k_disks and not quicktest",
210212
"name_filter": "not migration",
211213
},
212214
"largeblock-migrations": {
@@ -234,6 +236,7 @@
234236
],
235237
"nb_pools": 1,
236238
"params": {
239+
"--enable-reboot": True,
237240
"--vm": "single/small_vm",
238241
},
239242
"paths": ["tests/storage"],
@@ -376,6 +379,7 @@
376379
],
377380
"nb_pools": 1,
378381
"params": {
382+
"--enable-reboot": True,
379383
"--vm": "single/small_vm",
380384
},
381385
"paths": ["tests/xen"],
@@ -403,6 +407,8 @@
403407
],
404408
"nb_pools": 1,
405409
"params": {
410+
"--enable-reboot": True,
411+
"--enable-flaky": True,
406412
"--vm": "single/small_vm",
407413
},
408414
"paths": ["tests"],
@@ -425,7 +431,9 @@
425431
"The host will be rebooted by the tests."
426432
],
427433
"nb_pools": 1,
428-
"params": {},
434+
"params": {
435+
"--enable-reboot": True,
436+
},
429437
"paths": ["tests/pci_passthrough"],
430438
},
431439
"fs-diff": {
@@ -444,7 +452,9 @@
444452
"1 XCP-ng pool and an additionnal host >= 8.2"
445453
],
446454
"nb_pools": 2,
447-
"params": {},
455+
"params": {
456+
"--enable-reboot": True,
457+
},
448458
"paths": ["tests/misc/test_pool.py"],
449459
},
450460
"limit-tests": {

0 commit comments

Comments
 (0)