From 60d5d64d1afe4a4ffa2f54bcc4b6bf1ac0aba7d0 Mon Sep 17 00:00:00 2001 From: Marcello Dalponte <6449878+mdalp@users.noreply.github.com> Date: Wed, 3 Sep 2025 14:50:59 +0200 Subject: [PATCH] Resolve datetime.datetime.utcnow() deprecation --- newsfragments/3751.internal.rst | 1 + tests/core/utilities/test_encoding.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 newsfragments/3751.internal.rst diff --git a/newsfragments/3751.internal.rst b/newsfragments/3751.internal.rst new file mode 100644 index 0000000000..275310d421 --- /dev/null +++ b/newsfragments/3751.internal.rst @@ -0,0 +1 @@ +Resolve the DeprecationWarning for the usage of `datetime.datetime.utcnow()` diff --git a/tests/core/utilities/test_encoding.py b/tests/core/utilities/test_encoding.py index 82ec04c434..17fa0c6f48 100644 --- a/tests/core/utilities/test_encoding.py +++ b/tests/core/utilities/test_encoding.py @@ -144,8 +144,11 @@ def test_text_if_str_on_text(val): ), ( { - "date": [datetime.datetime.utcnow(), datetime.datetime.now()], - "other_date": datetime.datetime.utcnow().date(), + "date": [ + datetime.datetime.now(datetime.timezone.utc), + datetime.datetime.now(), + ], + "other_date": datetime.datetime.now(datetime.timezone.utc).date(), }, TypeError, "Could not encode to JSON: .*'other_date'.*is not JSON serializable",