Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default_ignore_list to be empty #540

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion freezegun/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ConfigurationError(Exception):
def configure(default_ignore_list: Optional[List[str]]=None, extend_ignore_list: Optional[List[str]]=None) -> None:
if default_ignore_list is not None and extend_ignore_list is not None:
raise ConfigurationError("Either default_ignore_list or extend_ignore_list might be given, not both")
if default_ignore_list:
if default_ignore_list is not None:
settings.default_ignore_list = default_ignore_list
if extend_ignore_list:
settings.default_ignore_list = list(dict.fromkeys([*settings.default_ignore_list, *extend_ignore_list]))
Expand Down
28 changes: 15 additions & 13 deletions tests/test_configure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest import mock
import pytest
import freezegun
import freezegun.config

Expand All @@ -10,32 +11,34 @@ def setup_function():
def teardown_function():
freezegun.config.reset_config()


def test_default_ignore_list_is_overridden():
freezegun.configure(default_ignore_list=['threading', 'tensorflow'])
@pytest.mark.parametrize('ignorelist', (
['threading', 'tensorflow'], # example from docs
[], # ignore nothing
))
def test_default_ignore_list_is_overridden(ignorelist):
freezegun.configure(default_ignore_list=list(ignorelist))

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 = [
'threading',
'tensorflow',
]

_freeze_time_init_mock.assert_called_once_with(
time_to_freeze_str="2020-10-06",
tz_offset=0,
ignore=expected_ignore_list,
ignore=ignorelist,
tick=False,
as_arg=False,
as_kwarg='',
auto_tick_seconds=0,
real_asyncio=False,
)

def test_extend_default_ignore_list():
freezegun.configure(extend_ignore_list=['tensorflow'])
@pytest.mark.parametrize('ignorelist', (
['tensorflow'], # example from docs
[], # ignore nothing extra
))
def test_extend_default_ignore_list(ignorelist):
freezegun.configure(extend_ignore_list=list(ignorelist))

with mock.patch("freezegun.api._freeze_time.__init__", return_value=None) as _freeze_time_init_mock:

Expand All @@ -54,8 +57,7 @@ def test_extend_default_ignore_list():
'_pytest.runner.',
'gi',
'prompt_toolkit',
'tensorflow',
]
] + ignorelist

_freeze_time_init_mock.assert_called_once_with(
time_to_freeze_str="2020-10-06",
Expand Down
Loading