From d2c1c08123de7c7690d122eaa4e562c90d770f46 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 26 Nov 2024 13:26:47 -0800 Subject: [PATCH] Use datetime.now instead of current_datetime The `microseconds=True` argument to `current_datetime` makes it equivalent to the much shorter and standard `datetime.now(tz=UTC)`. Use the standard construction and reserve `current_datetime` for the cases where we want to suppress the microseconds field. --- tests/handlers/api_tokens_test.py | 2 +- tests/support/logging.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/handlers/api_tokens_test.py b/tests/handlers/api_tokens_test.py index fb84eaef9..31c0bb182 100644 --- a/tests/handlers/api_tokens_test.py +++ b/tests/handlers/api_tokens_test.py @@ -943,7 +943,7 @@ async def test_create_admin( # Intentionally pass in a datetime with microseconds. They should be # stripped off so that the expiration is rounded to seconds, which we will # check when examining the log message. - now = current_datetime(microseconds=True) + now = datetime.now(tz=UTC) expires = now + timedelta(days=2) caplog.clear() r = await client.post( diff --git a/tests/support/logging.py b/tests/support/logging.py index 8d7ee461f..e7f2407f4 100644 --- a/tests/support/logging.py +++ b/tests/support/logging.py @@ -7,7 +7,6 @@ from typing import Any import pytest -from safir.datetime import current_datetime __all__ = ["parse_log"] @@ -33,7 +32,7 @@ def parse_log( List of parsed JSON dictionaries with the common log attributes removed (after validation). """ - now = current_datetime(microseconds=True) + now = datetime.now(tz=UTC) messages = [] for log_tuple in caplog.record_tuples: