Skip to content

Commit

Permalink
Merge pull request #540 from encukou/fix-empty-ignore
Browse files Browse the repository at this point in the history
Allow `default_ignore_list` to be empty
  • Loading branch information
bblommers authored Apr 22, 2024
2 parents 10f5124 + dde2630 commit 4ecad0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
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

0 comments on commit 4ecad0c

Please sign in to comment.