python: replace avocado tests with pytest
Following suit with the rest of this repository, drop avocado and replace it with the Python standard "pytest" package. Our ultimate goal is to merge these python tests with the meson test suite, so the use of 'pytest' here is only a stop-gap solution to get the GitLab CI 'check-python-tox' passing again following recent Python packaging ecosystem changes. Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260226213400.1254014-3-jsnow@redhat.com> [ran black autoformatter. --js] Signed-off-by: John Snow <jsnow@redhat.com>
John Snow committed
Feb 26, 2026 at 16:33 UTC
d5c6eef38ede2c79fcb92a015fa3c48c435740c7
4 files changed
+118
-2
python/Makefile
+2
-2
@@ -105,7 +105,7 @@ develop:
105
106
.PHONY: check
107
check:
108
- @avocado --config avocado.cfg run tests/
108
+ @pytest -v tests/*.py
109
110
.PHONY: check-tox
111
check-tox:
@@ -113,7 +113,7 @@ check-tox:
113
114
.PHONY: check-coverage
115
check-coverage:
116
- @coverage run -m avocado --config avocado.cfg run tests/*.py
116
+ @coverage run -m pytest -v tests/*.py
117
@coverage combine
118
@coverage html
119
@coverage report
python/setup.cfg
+1
@@ -43,6 +43,7 @@ devel =
43
mypy >= 1.4.0
44
pylint >= 2.17.3
45
pylint != 3.2.4; python_version<"3.9"
46
+ pytest >= 6.0.2
47
tox >= 3.18.0
48
sphinx >= 3.4.3
49
python/tests/linters.py
new
+114
@@ -0,0 +1,114 @@
1
+# SPDX-License-Identifier: GPL-2.0-or-later
2
+
3
+import os
4
+from subprocess import check_call
5
+import sys
6
+
7
+
8
+class TestLinters:
9
+
10
+ def test_flake8_pkg(self):
11
+ check_call([sys.executable, "-m", "flake8", "qemu/"])
12
+
13
+ def test_flake8_scripts(self):
14
+ check_call([sys.executable, "-m", "flake8", "scripts/"])
15
+
16
+ def test_flake8_qapi(self):
17
+ check_call(
18
+ [
19
+ sys.executable,
20
+ "-m",
21
+ "flake8",
22
+ "../scripts/qapi/",
23
+ "../docs/sphinx/qapidoc.py",
24
+ "../docs/sphinx/qapi_domain.py",
25
+ ]
26
+ )
27
+
28
+ def test_isort_pkg(self):
29
+ check_call([sys.executable, "-m", "isort", "-c", "qemu/"])
30
+
31
+ def test_isort_scripts(self):
32
+ check_call([sys.executable, "-m", "isort", "-c", "scripts/"])
33
+
34
+ def test_isort_qapi(self):
35
+ check_call(
36
+ [
37
+ sys.executable,
38
+ "-m",
39
+ "isort",
40
+ "--sp",
41
+ ".",
42
+ "-c",
43
+ "../scripts/qapi/",
44
+ ]
45
+ )
46
+
47
+ def test_isort_qapi_sphinx(self):
48
+ # Force isort to recognize 'compat' as a local module and not
49
+ # third-party
50
+ check_call(
51
+ [
52
+ sys.executable,
53
+ "-m",
54
+ "isort",
55
+ "--sp",
56
+ ".",
57
+ "-c",
58
+ "-p",
59
+ "compat",
60
+ "../docs/sphinx/qapi_domain.py",
61
+ "../docs/sphinx/qapidoc.py",
62
+ ]
63
+ )
64
+
65
+ def test_mypy_pkg(self):
66
+ check_call([sys.executable, "-m", "mypy", "-p", "qemu"])
67
+
68
+ def test_mypy_scripts(self):
69
+ check_call([sys.executable, "-m", "mypy", "scripts/"])
70
+
71
+ def test_mypy_qapi(self):
72
+ check_call([sys.executable, "-m", "mypy", "../scripts/qapi"])
73
+
74
+ def test_mypy_iotests(self):
75
+ check_call(
76
+ [sys.executable, "-m", "linters", "--mypy"],
77
+ cwd="../tests/qemu-iotests/",
78
+ )
79
+
80
+ # Setuptools v60 introduced the SETUPTOOLS_USE_DISTUTILS=stdlib
81
+ # workaround; stdlib distutils was fully removed in Python
82
+ # 3.12+. Once we are on >=3.12+ exclusively, this workaround can be
83
+ # dropped safely. Until then, it is needed for some versions on
84
+ # Fedora/Debian distributions which relied upon distro-patched
85
+ # setuptools present in CPython, but not within setuptools itself.
86
+
87
+ def test_pylint_pkg(self):
88
+ os.environ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib"
89
+ check_call([sys.executable, "-m", "pylint", "qemu/"])
90
+
91
+ def test_pylint_scripts(self):
92
+ os.environ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib"
93
+ check_call([sys.executable, "-m", "pylint", "scripts/"])
94
+
95
+ def test_pylint_qapi(self):
96
+ os.environ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib"
97
+ check_call(
98
+ [
99
+ sys.executable,
100
+ "-m",
101
+ "pylint",
102
+ "--rcfile=../scripts/qapi/pylintrc",
103
+ "../scripts/qapi/",
104
+ "../docs/sphinx/qapidoc.py",
105
+ "../docs/sphinx/qapi_domain.py",
106
+ ]
107
+ )
108
+
109
+ def test_pylint_iotests(self):
110
+ os.environ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib"
111
+ check_call(
112
+ [sys.executable, "-m", "linters", "--pylint"],
113
+ cwd="../tests/qemu-iotests/",
114
+ )
python/tests/minreqs.txt
+1
@@ -32,6 +32,7 @@ fusepy==2.0.4
32
33
# Test-runners, utilities, etc.
34
avocado-framework==90.0
35
+pytest==6.0.2
36
37
# Linters
38
flake8==5.0.4