[elbe-devel] [PATCH 08/10] elbepack: test_flake8; switch to pytest APIs

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon Mar 11 18:03:01 CET 2024


Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/tests/test_flake8.py | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/elbepack/tests/test_flake8.py b/elbepack/tests/test_flake8.py
index 929b29a0a5b9..5467b2976c2e 100644
--- a/elbepack/tests/test_flake8.py
+++ b/elbepack/tests/test_flake8.py
@@ -2,26 +2,27 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 # SPDX-FileCopyrightText: 2020 Linutronix GmbH
 
-from elbepack.commands.test import ElbeTestCase, ElbeTestException, system
+import glob
+
+from elbepack.commands.test import ElbeTestException, system
 from elbepack.directories import elbe_exe, pack_dir
-from elbepack.shellhelper import system_out
 
+import pytest
+
+
+flake8_opts = ['--max-line-length=100',
+               '--show-source']
 
-class TestPylint(ElbeTestCase):
-    flake8_opts = ['--max-line-length=100',
-                   '--show-source']
 
-    def test_lint(self):
-        files = system_out(f"find {pack_dir} -iname '*.py'").splitlines()
-        files.append(elbe_exe)
+def _python_files():
+    files = glob.glob(pack_dir + '/**/*.py', recursive=True)
+    files.append(elbe_exe)
+    return files
 
-        for f in files:
-            with self.subTest(file=f):
-                err_out = None
-                try:
-                    system(f"flake8 {' '.join(self.flake8_opts)} {f}")
-                except ElbeTestException as e:
-                    err_out = e.out
 
-                if err_out is not None:
-                    self.fail(err_out)
+ at pytest.mark.parametrize('f', _python_files())
+def test_flake8(f):
+    try:
+        system(f'flake8 {" ".join(flake8_opts)} {f}')
+    except ElbeTestException as e:
+        pytest.fail(e.out)

-- 
2.44.0



More information about the elbe-devel mailing list