From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>, "Kevin Wolf" <kwolf@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
qemu-block@nongnu.org, "John Snow" <jsnow@redhat.com>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Max Reitz" <mreitz@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Willian Rampazzo" <wrampazz@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Beraldo Leal" <bleal@redhat.com>
Subject: [PATCH v4 20/24] python: add pytest and tests
Date: Thu, 11 Feb 2021 13:58:52 -0500 [thread overview]
Message-ID: <20210211185856.3975616-21-jsnow@redhat.com> (raw)
In-Reply-To: <20210211185856.3975616-1-jsnow@redhat.com>
Try using pytest to manage our various tests; even though right now
they're only invoking binaries and not really running any python-native
code.
Create tests/, and add test_lint.py which calls out to mypy, flake8,
pylint and isort to enforce the standards in this directory.
Add pytest to the setup.cfg development dependencies; add a pytest
configuration section as well; run it in verbose mode.
Finally, add pytest to the Pipfile environment and lock the new
dependencies.
Provided you have the right development dependencies (mypy, flake8,
isort, pylint, and now pytest) You should be able to run "pytest" from
the python folder to run all of these linters with the correct
arguments.
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/Pipfile.lock | 57 ++++++++++++++++++++++++++++++++++++++-
python/setup.cfg | 5 ++++
python/tests/test_lint.py | 28 +++++++++++++++++++
3 files changed, 89 insertions(+), 1 deletion(-)
create mode 100644 python/tests/test_lint.py
diff --git a/python/Pipfile.lock b/python/Pipfile.lock
index 85b3124a491..0fa1a14a9b2 100644
--- a/python/Pipfile.lock
+++ b/python/Pipfile.lock
@@ -30,6 +30,14 @@
"markers": "python_version >= '3.5'",
"version": "==2.4.2"
},
+ "attrs": {
+ "hashes": [
+ "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6",
+ "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700"
+ ],
+ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
+ "version": "==20.3.0"
+ },
"flake8": {
"hashes": [
"sha256:749dbbd6bfd0cf1318af27bf97a14e28e5ff548ef8e5b1566ccfb25a11e7c839",
@@ -43,9 +51,16 @@
"sha256:ace61d5fc652dc280e7b6b4ff732a9c2d40db2c0f92bc6cb74e07b73d53a1771",
"sha256:fa5daa4477a7414ae34e95942e4dd07f62adf589143c875c133c1e53c4eff38d"
],
- "markers": "python_version < '3.8'",
+ "markers": "python_version < '3.8' and python_version < '3.8'",
"version": "==3.4.0"
},
+ "iniconfig": {
+ "hashes": [
+ "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3",
+ "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"
+ ],
+ "version": "==1.1.1"
+ },
"isort": {
"hashes": [
"sha256:c729845434366216d320e936b8ad6f9d681aab72dc7cbc2d51bedc3582f3ad1e",
@@ -123,6 +138,30 @@
],
"version": "==0.4.3"
},
+ "packaging": {
+ "hashes": [
+ "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5",
+ "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"
+ ],
+ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
+ "version": "==20.9"
+ },
+ "pluggy": {
+ "hashes": [
+ "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0",
+ "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"
+ ],
+ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
+ "version": "==0.13.1"
+ },
+ "py": {
+ "hashes": [
+ "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3",
+ "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"
+ ],
+ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
+ "version": "==1.10.0"
+ },
"pycodestyle": {
"hashes": [
"sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367",
@@ -147,6 +186,22 @@
"markers": "python_version >= '3.5'",
"version": "==2.6.0"
},
+ "pyparsing": {
+ "hashes": [
+ "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1",
+ "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"
+ ],
+ "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'",
+ "version": "==2.4.7"
+ },
+ "pytest": {
+ "hashes": [
+ "sha256:9d1edf9e7d0b84d72ea3dbcdfd22b35fb543a5e8f2a60092dd578936bf63d7f9",
+ "sha256:b574b57423e818210672e07ca1fa90aaf194a4f63f3ab909a2c67ebb22913839"
+ ],
+ "markers": "python_version >= '3.6'",
+ "version": "==6.2.2"
+ },
"qemu": {
"editable": true,
"path": "."
diff --git a/python/setup.cfg b/python/setup.cfg
index 11c361501e8..2c5943277d7 100644
--- a/python/setup.cfg
+++ b/python/setup.cfg
@@ -26,6 +26,7 @@ devel =
isort >= 5.0.5
mypy >= 0.770
pylint >= 2.6.0
+ pytest >= 3.0.0
[flake8]
@@ -73,3 +74,7 @@ include_trailing_comma=True
line_length=72
lines_after_imports=2
multi_line_output=3
+
+[tool:pytest]
+addopts = -v
+console_output_style = count
diff --git a/python/tests/test_lint.py b/python/tests/test_lint.py
new file mode 100644
index 00000000000..38fefa01c66
--- /dev/null
+++ b/python/tests/test_lint.py
@@ -0,0 +1,28 @@
+import subprocess
+
+
+def _external_test(command_line: str) -> None:
+ args = command_line.split(' ')
+ try:
+ subprocess.run(args, check=True)
+ except subprocess.CalledProcessError as err:
+ # Re-contextualize to avoid pytest showing error context inside
+ # the subprocess module itself
+ raise Exception("'{:s}' returned {:d}".format(
+ ' '.join(args), err.returncode)) from None
+
+
+def test_isort() -> None:
+ _external_test('isort -c qemu')
+
+
+def test_flake8() -> None:
+ _external_test('flake8')
+
+
+def test_pylint() -> None:
+ _external_test('pylint qemu')
+
+
+def test_mypy() -> None:
+ _external_test('mypy -p qemu')
--
2.29.2
next prev parent reply other threads:[~2021-02-11 19:34 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-11 18:58 [PATCH v4 00/24] python: create installable package John Snow
2021-02-11 18:58 ` [PATCH v4 01/24] python/console_socket: avoid one-letter variable John Snow
2021-02-12 4:47 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 02/24] iotests/297: add --namespace-packages to mypy arguments John Snow
2021-02-12 4:53 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 03/24] python: create qemu packages John Snow
2021-02-12 5:17 ` Cleber Rosa
2021-02-15 20:31 ` John Snow
2021-02-11 18:58 ` [PATCH v4 04/24] python: create utils sub-package John Snow
2021-02-17 1:20 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 05/24] python: add qemu package installer John Snow
2021-02-17 2:23 ` Cleber Rosa
2021-02-17 3:38 ` John Snow
2021-02-11 18:58 ` [PATCH v4 06/24] python: add VERSION file John Snow
2021-02-17 2:26 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 07/24] python: add directory structure README.rst files John Snow
2021-02-17 2:47 ` Cleber Rosa
2021-02-18 17:45 ` John Snow
2021-02-11 18:58 ` [PATCH v4 08/24] python: Add pipenv support John Snow
2021-02-17 2:59 ` Cleber Rosa
2021-02-17 3:02 ` Cleber Rosa
2021-02-17 17:28 ` John Snow
2021-02-17 19:39 ` Cleber Rosa
2021-02-17 3:42 ` John Snow
2021-02-11 18:58 ` [PATCH v4 09/24] python: add pylint import exceptions John Snow
2021-02-17 3:07 ` Cleber Rosa
2021-02-17 3:44 ` John Snow
2021-02-11 18:58 ` [PATCH v4 10/24] python: move pylintrc into setup.cfg John Snow
2021-02-17 3:09 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 11/24] python: add pylint to pipenv John Snow
2021-02-17 4:12 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 12/24] python: move flake8 config to setup.cfg John Snow
2021-02-17 4:17 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 13/24] python: Add flake8 to pipenv John Snow
2021-02-17 4:20 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 14/24] python: move mypy.ini into setup.cfg John Snow
2021-02-11 18:58 ` [PATCH v4 15/24] python: add mypy to pipenv John Snow
2021-02-17 4:38 ` Cleber Rosa
2021-02-17 16:40 ` John Snow
2021-02-11 18:58 ` [PATCH v4 16/24] python: move .isort.cfg into setup.cfg John Snow
2021-02-17 4:44 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 17/24] python/qemu: add isort to pipenv John Snow
2021-02-17 4:45 ` Cleber Rosa
2021-02-11 18:58 ` [PATCH v4 18/24] python/qemu: add qemu package itself " John Snow
2021-02-17 4:47 ` Cleber Rosa
2021-02-17 16:42 ` John Snow
2021-02-11 18:58 ` [PATCH v4 19/24] python: add devel package requirements to setuptools John Snow
2021-02-11 18:58 ` John Snow [this message]
2021-02-11 18:58 ` [PATCH v4 21/24] python: add excluded dirs to flake8 config John Snow
2021-02-11 18:58 ` [PATCH v4 22/24] python: add Makefile for some common tasks John Snow
2021-02-11 18:58 ` [PATCH v4 23/24] python: add .gitignore John Snow
2021-02-11 18:58 ` [PATCH v4 24/24] gitlab: add python linters to CI John Snow
2021-02-12 2:52 ` [PATCH v4 00/24] python: create installable package Cleber Rosa
2021-02-15 21:32 ` John Snow
2021-02-17 3:37 ` Cleber Rosa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210211185856.3975616-21-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=wainersm@redhat.com \
--cc=wrampazz@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).