Skip to content

Commit 8b152db

Browse files
authored
Freeze format_time() tests to a specific date to fix test failures (#998)
Freeze the date when performing the tests for format_time() with a timezone specified. Since the time object does not specify a date, the formatter uses the format string specific to the current date. As a result, if the current DST state is different than when the test was last updated, it failed.
1 parent 134c792 commit 8b152db

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tests/test_dates.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,13 @@ def test_format_time(timezone_getter):
601601
custom = dates.format_time(t, "hh 'o''clock' a, zzzz", tzinfo=eastern, locale='en')
602602
assert custom == "09 o'clock AM, Eastern Daylight Time"
603603

604-
t = time(15, 30)
605-
paris = dates.format_time(t, format='full', tzinfo=paris, locale='fr_FR')
606-
assert paris == '15:30:00 heure normale d’Europe centrale'
604+
with freezegun.freeze_time("2023-01-01"):
605+
t = time(15, 30)
606+
paris = dates.format_time(t, format='full', tzinfo=paris, locale='fr_FR')
607+
assert paris == '15:30:00 heure normale d’Europe centrale'
607608

608-
us_east = dates.format_time(t, format='full', tzinfo=eastern, locale='en_US')
609-
assert us_east == '3:30:00\u202fPM Eastern Standard Time'
609+
us_east = dates.format_time(t, format='full', tzinfo=eastern, locale='en_US')
610+
assert us_east == '3:30:00\u202fPM Eastern Standard Time'
610611

611612

612613
def test_format_skeleton(timezone_getter):

0 commit comments

Comments
 (0)