Skip to content

Commit bf80097

Browse files
committed
remove use of utcnow
1 parent bae9823 commit bf80097

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

tests/benchmarks/test_micro_benchmarks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ class CoreModel:
760760

761761
@pytest.fixture(scope='class')
762762
def datetime_raw(self):
763-
return datetime.utcnow().replace(tzinfo=timezone.utc) + timedelta(days=1)
763+
return datetime.now(timezone.utc) + timedelta(days=1)
764764

765765
@pytest.fixture(scope='class')
766766
def datetime_str(self, datetime_raw):

tests/validators/test_date.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def test_date_future(py_and_json: PyAndJson, input_value, expected):
275275

276276
def test_date_past_future_today():
277277
v = SchemaValidator(core_schema.date_schema(now_op='past', now_utc_offset=0))
278-
today = datetime.utcnow().replace(tzinfo=timezone.utc).date()
278+
today = datetime.now(timezone.utc).date()
279279
assert v.isinstance_python(today) is False
280280
assert v.isinstance_python(today - timedelta(days=1)) is True
281281
assert v.isinstance_python(today + timedelta(days=1)) is False

tests/validators/test_datetime.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def test_datetime_past(py_and_json: PyAndJson, input_value, expected):
307307

308308
def test_datetime_past_timezone():
309309
v = SchemaValidator(core_schema.datetime_schema(now_utc_offset=0, now_op='past'))
310-
now_utc = datetime.utcnow().replace(tzinfo=timezone.utc) - timedelta(seconds=1)
310+
now_utc = datetime.now(timezone.utc) - timedelta(seconds=1)
311311
assert v.isinstance_python(now_utc)
312312
# "later" in the day
313313
assert v.isinstance_python(now_utc.astimezone(pytz.timezone('Europe/Istanbul')))
@@ -350,7 +350,7 @@ def test_datetime_future(py_and_json: PyAndJson, input_value, expected):
350350

351351
def test_datetime_future_timezone():
352352
v = SchemaValidator(core_schema.datetime_schema(now_utc_offset=0, now_op='future'))
353-
now_utc = datetime.utcnow().replace(tzinfo=timezone.utc)
353+
now_utc = datetime.now(timezone.utc)
354354

355355
soon_utc = now_utc + timedelta(minutes=1)
356356
assert v.isinstance_python(soon_utc)
@@ -376,10 +376,10 @@ def test_mock_utc_offset_8_hours(mocker):
376376
"""
377377
mocker.patch('time.localtime', return_value=type('time.struct_time', (), {'tm_gmtoff': 8 * 60 * 60}))
378378
v = SchemaValidator(core_schema.datetime_schema(now_op='future'))
379-
future = datetime.utcnow() + timedelta(hours=8, minutes=1)
379+
future = datetime.now(timezone.utc).replace(tzinfo=None) + timedelta(hours=8, minutes=1)
380380
assert v.isinstance_python(future)
381381

382-
future = datetime.utcnow() + timedelta(hours=7, minutes=59)
382+
future = datetime.now(timezone.utc).replace(tzinfo=None) + timedelta(hours=7, minutes=59)
383383
assert not v.isinstance_python(future)
384384

385385

0 commit comments

Comments
 (0)