From f6b230711036e1b4089955687475cfc207dc7886 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sun, 17 Mar 2024 19:23:22 -0100 Subject: [PATCH] Bug Repro: FakeDatetime should be real when part of ignored_modules --- tests/test_configure.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_configure.py b/tests/test_configure.py index 930e3fe..6b0bfca 100644 --- a/tests/test_configure.py +++ b/tests/test_configure.py @@ -1,3 +1,5 @@ +import datetime +import sys from unittest import mock import freezegun import freezegun.config @@ -104,3 +106,22 @@ def test_extend_default_ignore_list_duplicate_items(): auto_tick_seconds=0, real_asyncio=False, ) + +FROZEN_DATETIME = datetime.datetime(2020, 2, 29, 0, 0, 0, tzinfo=datetime.timezone.utc) +current = datetime.datetime.now(datetime.timezone.utc) + + +def test_fakedatetime_is_ignored(): + from . import another_module + + with freezegun.freeze_time(FROZEN_DATETIME): + + assert another_module.gmtime().tm_year == FROZEN_DATETIME.year + assert another_module.FakeDatetime.now().year == FROZEN_DATETIME.year + + with freezegun.freeze_time(FROZEN_DATETIME, ignore=["tests.another_module"]): + + assert another_module.gmtime().tm_year == current.year + assert another_module.FakeDatetime.now().year == current.year + + del sys.modules["tests.another_module"]