From: Zbigniew Jędrzejewski-Szmek Date: Sat, 22 Apr 2023 11:10:28 +0000 (+0200) Subject: test_ukify: rework how --flakes argument is appended X-Git-Tag: v254-rc1~548^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55be961f48cfb5116776bf43956eb3b9600a3f0d;p=thirdparty%2Fsystemd.git test_ukify: rework how --flakes argument is appended 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.) --- diff --git a/src/ukify/test/meson.build b/src/ukify/test/meson.build index e39178f8925..e78e76c673c 100644 --- a/src/ukify/test/meson.build +++ b/src/ukify/test/meson.build @@ -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 index 1f655da8344..00000000000 --- a/src/ukify/test/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[tool:pytest] -addopts = --flakes diff --git a/src/ukify/test/test_ukify.py b/src/ukify/test/test_ukify.py index 1013f649bed..3cd895fe36d 100755 --- a/src/ukify/test/test_ukify.py +++ b/src/ukify/test/test_ukify.py @@ -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))