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_requirements.py b/test/unit/test_requirements.py index 42cb017c..1297c7cb 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 @@ -27,13 +29,15 @@ 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'] +def test_skip_bad_formats(capsys): + """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():