Skip to content

tests: Fix deprecation warning for utcfromtimestamp() - #3354

Merged
vvoland merged 1 commit into
docker:mainfrom
ricardobranco777:timezone_aware
Sep 14, 2026
Merged

vvoland merged 1 commit into
docker:mainfrom
ricardobranco777:timezone_aware

Conversation

@ricardobranco777

@ricardobranco777 ricardobranco777 commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

Fix DeprecationWarning for datetime.datetime.utcfromtimestamp()

It suggests to use timezone-aware objects to represent datetimes in UTC with datetime.UTC but datetime.timezone.utc is backwards compatible.

Verification run: https://openqa.opensuse.org/tests/5261910#downloads

tests/unit/api_container_test.py::ContainerTest::test_log_since_with_datetime
  /src/tests/unit/api_container_test.py:1305: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    time = datetime.datetime.utcfromtimestamp(ts)

tests/unit/api_test.py::DockerApiTest::test_events_with_since_until
  /src/tests/unit/api_test.py:234: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    now = datetime.datetime.utcfromtimestamp(ts)

@ricardobranco777

ricardobranco777 commented Aug 23, 2025

Copy link
Copy Markdown
Contributor Author

Fixes deprecation warning noticed in #3335

cc @thaJeztah

Fix DeprecationWarning for datetime.datetime.utcfromtimestamp()

It suggests to use timezone-aware objects to represent datetimes in UTC
with datetime.UTC but datetime.timezone.utc is backwards compatible.

Signed-off-by: Ricardo Branco <rbranco@suse.de>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused test updates correctly eliminate the warnings without changing expected behavior.

Pull request overview

Updates datetime-based API tests to avoid Python’s deprecated utcfromtimestamp() while preserving UTC behavior.

Changes:

  • Replaces deprecated calls with timezone-aware fromtimestamp(..., timezone.utc).
  • Keeps expected Unix timestamps unchanged.
File summaries
File Description
tests/unit/api_test.py Updates event time-range test.
tests/unit/api_container_test.py Updates container log timestamp test.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@vvoland
vvoland merged commit f387c3f into docker:main Sep 14, 2026
15 checks passed
@ricardobranco777
ricardobranco777 deleted the timezone_aware branch September 14, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants