git: 97760572a0e4 - main - testing: add public method for requiring module presense in pytest
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 15 May 2023 10:53:39 UTC
The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=97760572a0e4c287a67730df80e7a7b4cf735977 commit 97760572a0e4c287a67730df80e7a7b4cf735977 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-05-15 10:50:55 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-05-15 10:50:55 +0000 testing: add public method for requiring module presense in pytest MFC after: 2 weeks --- tests/atf_python/utils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/atf_python/utils.py b/tests/atf_python/utils.py index 1c0a68dad383..4bd4b642b131 100644 --- a/tests/atf_python/utils.py +++ b/tests/atf_python/utils.py @@ -47,14 +47,21 @@ class BaseTest(object): TARGET_USER = None # Set to the target user by the framework REQUIRED_MODULES: List[str] = [] + def require_module(self, mod_name: str, skip=True): + error_code = libc.modfind(mod_name) + if error_code == 0: + return + err_str = os.strerror(error_code) + txt = "kernel module '{}' not available: {}".format(mod_name, err_str) + if skip: + pytest.skip(txt) + else: + raise ValueError(txt) + def _check_modules(self): for mod_name in self.REQUIRED_MODULES: - error_code = libc.modfind(mod_name) - if error_code != 0: - err_str = os.strerror(error_code) - pytest.skip( - "kernel module '{}' not available: {}".format(mod_name, err_str) - ) + self.require_module(mod_name) + @property def atf_vars(self) -> Dict[str, str]: px = "_ATF_VAR_"