From 8193af6f916ef2cf88f94ddda9966e8adf5075d4 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 16 Aug 2023 09:52:38 -0700 Subject: [PATCH] make CI green Signed-off-by: Abhijeet Kasurde --- .../_target_scripts/introspect.py | 5 +++-- test/conftest.py | 2 ++ test/unit/test_introspect.py | 2 +- test/unit/test_requirements.py | 16 ++++++++++------ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/ansible_builder/_target_scripts/introspect.py b/src/ansible_builder/_target_scripts/introspect.py index a132ea81..46f81242 100644 --- a/src/ansible_builder/_target_scripts/introspect.py +++ b/src/ansible_builder/_target_scripts/introspect.py @@ -344,8 +344,9 @@ def sanitize_requirements(collection_py_reqs): consolidated.append(req) seen_pkgs.add(req.name) except Exception as e: - logger.error('Failed to parse requirements from %s, error: %s', collection, e) - sys.exit(1) + msg = f'Failed to parse requirements from {collection}, error: {e}' + logger.error(msg) + sys.exit(msg) # removal of unwanted packages sanitized = [] diff --git a/test/conftest.py b/test/conftest.py index ec4ad77e..32e3fc45 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -46,6 +46,8 @@ def pytest_sessionfinish(session, exitstatus): # If we are the main worker thread, we've been called last, so do the cleanup. if worker_id is None: for runtime in CONTAINER_RUNTIMES: + if runtime not in FOUND_RUNTIMES: + continue data_file = pathlib.Path(base_tmpfile + runtime) if data_file.exists(): for image_name in data_file.read_text().split("\n"): diff --git a/test/unit/test_introspect.py b/test/unit/test_introspect.py index f91f0dc6..42af8700 100644 --- a/test/unit/test_introspect.py +++ b/test/unit/test_introspect.py @@ -72,4 +72,4 @@ def test_parse_args_default_action(): def test_corrupt_python_requirements(): with pytest.raises(SystemExit) as excinfo: sanitize_requirements({'test.metadata': ['invalid_package=1']}) - assert excinfo.value.code == 1 + assert excinfo.value.code.startswith('Failed to parse requirements from') diff --git a/test/unit/test_requirements.py b/test/unit/test_requirements.py index 42cb017c..f33aeb6a 100644 --- a/test/unit/test_requirements.py +++ b/test/unit/test_requirements.py @@ -1,3 +1,5 @@ +import pytest + from ansible_builder._target_scripts.introspect import sanitize_requirements @@ -28,12 +30,14 @@ def test_remove_unwanted_requirements(): def test_skip_bad_formats(): - """A single incorrectly formatted requirement should warn, but not block other reqs""" - assert sanitize_requirements({'foo.bar': [ - 'foo', - 'bar' - ], 'foo.bad': ['zizzer zazzer zuzz'] # not okay - }) == ['foo # from collection foo.bar', 'bar # from collection foo.bar'] + """A single incorrectly formatted requirement should raise error""" + + with pytest.raises(SystemExit) as exc_info: + sanitize_requirements({ + 'foo.bar': ['foo', 'bar'], + 'foo.bad': ['zizzer zazzer zuzz'] # not okay + }) + assert exc_info.value.code.startswith('Failed to parse requirements') def test_sanitize_requirements_do_not_exclude():