From 3ef27b7363937f75f9ced2a336b62657643047c4 Mon Sep 17 00:00:00 2001 From: Matthew Hawn Date: Thu, 22 Sep 2022 15:43:20 -0600 Subject: [PATCH 1/2] clear lru_cache. Fixes #611 --- detect_secrets/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/detect_secrets/settings.py b/detect_secrets/settings.py index e4bd9d8b..97020000 100644 --- a/detect_secrets/settings.py +++ b/detect_secrets/settings.py @@ -71,6 +71,7 @@ def default_settings() -> Generator['Settings', None, None]: for plugin_type in get_mapping_from_secret_type_to_class().values() ], }) as settings: + get_mapping_from_secret_type_to_class.cache_clear() yield settings From 88de6b67701098767fab2e5e3ce3f454cab28877 Mon Sep 17 00:00:00 2001 From: Matthew Hawn Date: Thu, 22 Sep 2022 17:05:16 -0600 Subject: [PATCH 2/2] Fixup filter/plugin testing --- testing/plugins.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/testing/plugins.py b/testing/plugins.py index 5a5957fc..8c08dfec 100644 --- a/testing/plugins.py +++ b/testing/plugins.py @@ -2,6 +2,7 @@ from contextlib import contextmanager from typing import Any from typing import Generator +from unittest import mock from detect_secrets.core.plugins import Plugin from detect_secrets.core.plugins.util import get_mapping_from_secret_type_to_class @@ -19,9 +20,16 @@ def get_instance(*args: Any, **kwargs: Any) -> Plugin: # registered plugins, this shimmed function will be known as the underlying plugin class. get_instance.__name__ = plugin.__class__.__name__ + get_mapping_from_secret_type_to_class.cache_clear() + mapping = get_mapping_from_secret_type_to_class() + mapping[plugin.secret_type] = get_instance # type: ignore + try: - get_mapping_from_secret_type_to_class()[plugin.secret_type] = get_instance # type: ignore - yield + with mock.patch( + 'detect_secrets.core.plugins.util.get_mapping_from_secret_type_to_class', + return_value = mapping + ): + yield finally: # On next run, it should re-initialize to base state. get_mapping_from_secret_type_to_class.cache_clear()