From 6962064c3f0e4ad82f2cbd5b4f78cfa8cc7a2175 Mon Sep 17 00:00:00 2001 From: William Murphy Date: Tue, 3 Oct 2023 08:46:06 -0400 Subject: [PATCH] chore: assert no exceptions logged during test run (#311) The provider is intentionally resilient to malformed records, and implements this resilience by logging and continuing on when any exception is thrown. However, this prevents the unit tests from many errors in the implementation of the provider. Therefore, spy on the provider and fail unit tests if it is logging exceptions. Signed-off-by: Will Murphy Signed-off-by: Andrew Nesbitt --- tests/unit/providers/debian/test_debian.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/providers/debian/test_debian.py b/tests/unit/providers/debian/test_debian.py index 17dcafae..138793ae 100644 --- a/tests/unit/providers/debian/test_debian.py +++ b/tests/unit/providers/debian/test_debian.py @@ -2,6 +2,7 @@ import os.path import shutil +from unittest.mock import MagicMock import pytest from vunnel import result, workspace @@ -68,6 +69,7 @@ def test_get_dsa_map(self, tmpdir, helpers, disable_get_requests): def test_normalize_json(self, tmpdir, helpers, disable_get_requests): subject = parser.Parser(workspace=workspace.Workspace(tmpdir, "test", create=True)) + subject.logger = MagicMock() dsa_mock_data_path = helpers.local_dir(self._sample_dsa_data_) json_mock_data_path = helpers.local_dir(self._sample_json_data_) @@ -88,6 +90,7 @@ def test_normalize_json(self, tmpdir, helpers, disable_get_requests): assert all(x.get("Vulnerability", {}).get("Name") for x in vuln_dict.values()) assert all(x.get("Vulnerability", {}).get("Description") is not None for x in vuln_dict.values()) + assert not subject.logger.exception.called, "no exceptions should be logged" def test_get_legacy_records(self, tmpdir, helpers, disable_get_requests): subject = parser.Parser(workspace=workspace.Workspace(tmpdir, "test", create=True))