From b5a42dbf382098b8f64e0d8e4a4cf0168f597568 Mon Sep 17 00:00:00 2001 From: Loukas Leontopoulos <3223314+lleontop@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:37:47 +0000 Subject: [PATCH] Ignore duplicate modules in ignore list Ignore duplicate modules passed in ignore_list. This could also be done with calling `set` on the final ignore list but sets are unordered which in terms of functionality I reckon should be ok but it was a pain in tests, so opted for a this `dict.fromkeys` way since supported python versions are >=3.7 --- freezegun/config.py | 2 +- tests/test_configure.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/freezegun/config.py b/freezegun/config.py index 6d9d640..79b70f2 100644 --- a/freezegun/config.py +++ b/freezegun/config.py @@ -35,7 +35,7 @@ def configure(default_ignore_list: Optional[List[str]]=None, extend_ignore_list: if default_ignore_list: settings.default_ignore_list = default_ignore_list if extend_ignore_list: - settings.default_ignore_list = [*settings.default_ignore_list, *extend_ignore_list] + settings.default_ignore_list = list(dict.fromkeys([*settings.default_ignore_list, *extend_ignore_list])) def reset_config() -> None: diff --git a/tests/test_configure.py b/tests/test_configure.py index 970b141..930e3fe 100644 --- a/tests/test_configure.py +++ b/tests/test_configure.py @@ -67,3 +67,40 @@ def test_extend_default_ignore_list(): auto_tick_seconds=0, real_asyncio=False, ) + +def test_extend_default_ignore_list_duplicate_items(): + freezegun.configure(extend_ignore_list=['tensorflow', 'pymongo', 'tensorflow','rabbitmq']) + freezegun.configure(extend_ignore_list=['tensorflow']) + + with mock.patch("freezegun.api._freeze_time.__init__", return_value=None) as _freeze_time_init_mock: + + freezegun.freeze_time("2020-10-06") + + expected_ignore_list = [ + 'nose.plugins', + 'six.moves', + 'django.utils.six.moves', + 'google.gax', + 'threading', + 'multiprocessing', + 'queue', + 'selenium', + '_pytest.terminal.', + '_pytest.runner.', + 'gi', + 'prompt_toolkit', + 'tensorflow', + 'pymongo', + 'rabbitmq', + ] + + _freeze_time_init_mock.assert_called_once_with( + time_to_freeze_str="2020-10-06", + tz_offset=0, + ignore=expected_ignore_list, + tick=False, + as_arg=False, + as_kwarg='', + auto_tick_seconds=0, + real_asyncio=False, + )