From a40f87e7d1252fe8a1bf94195dda67662c9ca7bf Mon Sep 17 00:00:00 2001 From: jobrauer Date: Mon, 24 Feb 2020 11:09:36 +0100 Subject: [PATCH] Address CRW - add pytest.raises - add **kwargs in PackagingUtility.run(...) --- .../test_buildrequire_invalid_module.py | 57 +++++++++---------- tests/integration/utils.py | 10 ++-- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/tests/integration/test_buildrequire_invalid_module.py b/tests/integration/test_buildrequire_invalid_module.py index 02d2bc7b..cc14cd20 100644 --- a/tests/integration/test_buildrequire_invalid_module.py +++ b/tests/integration/test_buildrequire_invalid_module.py @@ -4,42 +4,39 @@ import pytest from sh import ErrorReturnCode -# expected error message -CANNOT_FIND_ANY_MODULE_BUILDS = "Cannot find any module builds" # ... - - def test_buildrequire_invalid_module(pkg_util, scenario, repo, koji): """ - Run a build with with an invalid 'build_require' module. - I.e.: required module is picked in such a way, - that it is not tagged according to the the base module (platform) requirements, - see platform's modulemd file and its 'koji_tag_with_modules' attribute - (e.g.: platform: el-8.1.0 --> rhel-8.1.0-modules-build). + Run a build with with an invalid 'build_require' module. + I.e.: required module is picked in such a way, + that it is not tagged according to the the base module (platform) requirements, + see platform's modulemd file and its 'koji_tag_with_modules' attribute + (e.g.: platform: el-8.1.0 --> rhel-8.1.0-modules-build). - Koji resolver is expected to not be able to satisfy this build requirement - and hence fail the build. + Koji resolver is expected to not be able to satisfy this build requirement + and hence fail the build. - Assert that: - * the module build hasn't been accepted by MBS: - rhpkg utility returns something else than 0 - * "Cannot find any module build..." found on STDERR + Assert that: + * the module build hasn't been accepted by MBS: + rhpkg utility returns something else than 0 + * "Cannot find any module build..." found on STDERR - If assert fails: - * cancel all triggered module builds. + If assert fails: + * cancel all triggered module builds. - """ + """ repo.bump() - try: - builds = pkg_util.run("--optional", "rebuild_strategy=all") - - for build in builds: - print("Canceling module-build {}...".format(build.id)) - pkg_util.cancel(build) - - pytest.fail("Invalid 'build_require' was satisfied and module build was accepted by MBS!") - - except ErrorReturnCode as e: - # expected outcome: build submission fails - assert CANNOT_FIND_ANY_MODULE_BUILDS in e.stderr.decode("utf-8") + expected_error = "Cannot find any module builds" + with pytest.raises(ErrorReturnCode) as excinfo: + # Override 'baked' (_err=sys.stderr) stderr redirect: + # Here we are fine with what plain sh.Command gives us + # (otherwise ErrorReturnCode.stderr is incomplete). + builds = pkg_util.run("--optional", "rebuild_strategy=all", _err=None) + try: + for build in builds: + print("Canceling module-build {}...".format(build.id)) + pkg_util.cancel(build) + except: + pass + assert expected_error in excinfo.value.stderr.decode("utf-8") diff --git a/tests/integration/utils.py b/tests/integration/utils.py index 5642c58f..62dcbc00 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -167,15 +167,13 @@ class PackagingUtility: def __init__(self, packaging_utility, mbs_api): self._packaging_utility = Command(packaging_utility).bake( - # review: is redirect necessary? - # In case of failure, I can't find the stderr in the resulting exception object.. - # _out=sys.stdout, - # _err=sys.stderr, + _out=sys.stdout, + _err=sys.stderr, _tee=True ) self._mbs_api = mbs_api - def run(self, *args, reuse=None): + def run(self, *args, reuse=None, **kwargs): """Run one or more module builds :param args: Options and arguments for the build command @@ -195,7 +193,7 @@ class PackagingUtility: else: build_ids = [reuse] else: - stdout = self._packaging_utility("module-build", *args).stdout.decode("utf-8") + stdout = self._packaging_utility("module-build", *args, **kwargs).stdout.decode("utf-8") build_ids = re.findall(self._mbs_api + r"module-builds/(\d+)", stdout) return [Build(self._mbs_api, int(build_id)) for build_id in build_ids]