From 6eb9b5af6bfd2357b8bfa8cf568613b2037fc51f Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 17 Jul 2025 11:31:06 +0100 Subject: [PATCH] Fix Python 3.12+ datetime.utcnow() deprecation warning Python 3.12 deprecated datetime.utcnow() in favour of `datetime.now(timezone.utc): https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow . This PR updates the timestamp calculation in a backwards-compatible way to avoid the deprecation warning. --- pytest_textual_snapshot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest_textual_snapshot.py b/pytest_textual_snapshot.py index 44c5fd4..5a06ba3 100644 --- a/pytest_textual_snapshot.py +++ b/pytest_textual_snapshot.py @@ -6,7 +6,7 @@ import re import shutil from dataclasses import dataclass -from datetime import datetime +from datetime import datetime, timezone from operator import attrgetter from os import PathLike from pathlib import Path, PurePath @@ -369,7 +369,7 @@ def save_svg_diffs( pass_percentage=100 * (num_snapshots_passing / max(num_snapshot_tests, 1)), fail_percentage=100 * (num_fails / max(num_snapshot_tests, 1)), num_snapshot_tests=num_snapshot_tests, - now=datetime.utcnow(), + now=datetime.now(tz=timezone.utc), file_open_prefix=os.getenv("TEXTUAL_SNAPSHOT_FILE_OPEN_PREFIX", "file://"), ) with open(snapshot_report_path, "w+", encoding="utf-8") as snapshot_file: