Skip to content

Commit

Permalink
Use datetime.now instead of current_datetime
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rra committed Nov 27, 2024
1 parent 3e6491e commit d2c1c08
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/handlers/api_tokens_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions tests/support/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Any

import pytest
from safir.datetime import current_datetime

__all__ = ["parse_log"]

Expand All @@ -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:
Expand Down

0 comments on commit d2c1c08

Please sign in to comment.