]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test_ukify: rework how --flakes argument is appended
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 22 Apr 2023 11:10:28 +0000 (13:10 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 5 May 2023 16:42:37 +0000 (18:42 +0200)
The usual approach is to put 'addopts = --flakes' in setup.cfg. Unfortunately
this fails badly when pytest-flakes is not installed:
  ERROR: usage: test_ukify.py [options] [file_or_dir] [file_or_dir] [...]
  test_ukify.py: error: unrecognized arguments: --flakes

pytest-flakes is not packaged everywhere, and this test is not very important,
so let's just do it only if pytest-flakes is available. We now detect if
pytest-flakes is available and only add '--flakes' conditionally. This
unfortunately means that when invoked via 'pytest' or directly as
'src/ukify/test/test_ukify.py', '--flakes' will not be appended automatically.
But I don't see a nice way to achieve previous automatic behaviour.

(I first considered making 'setup.cfg' templated. But then it is created
in the build directory, but we would need it in the source directory for
pytest to load it automatically. So to load the file, we'd need to give an
argument to pytest anyway, so we don't gain anything with this more complex
approach.)

src/ukify/test/meson.build
src/ukify/test/setup.cfg [deleted file]
src/ukify/test/test_ukify.py

index e39178f89256af88b020a23b3a61adbd5e79513c..e78e76c673cec6a44983492490f04a6d779d5ae7 100644 (file)
@@ -1,7 +1,19 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
 if want_ukify and want_tests != 'false'
-   test('test-ukify',
-        files('test_ukify.py'),
-        env : test_env)
+        have_pytest_flakes = pymod.find_installation(
+                'python3',
+                required : false,
+                modules : ['pytest_flakes'],
+        ).found()
+
+        args = ['-v']
+        if have_pytest_flakes
+                args += ['--flakes']
+        endif
+
+        test('test-ukify',
+             files('test_ukify.py'),
+             args: args,
+             env : test_env)
 endif
diff --git a/src/ukify/test/setup.cfg b/src/ukify/test/setup.cfg
deleted file mode 100644 (file)
index 1f655da..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-[tool:pytest]
-addopts = --flakes
index 1013f649bed464568dc06221a10474ef7b7a1b46..3cd895fe36d033e5e16644041a3ee53e4c84cbd1 100755 (executable)
@@ -495,4 +495,4 @@ def test_pcr_signing2(kernel_initrd, tmpdir):
     assert len(sig['sha1']) == 6   # six items for six phases paths
 
 if __name__ == '__main__':
-    sys.exit(pytest.main([__file__, '-v']))
+    sys.exit(pytest.main(sys.argv))