Skip to content

DeprecationWarning warning in build log for python 3.12 datetime.datetime.utcfromtimestamp() is deprecated #818

Closed
@parthea

Description

@parthea

See warning below which appears in the Kokoro build log

tests/unit/handlers/transports/test_background_thread.py: 11 warnings
  /tmpfs/src/github/python-logging/google/cloud/logging_v2/handlers/transports/background_thread.py:243: 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).
    "timestamp": datetime.datetime.utcfromtimestamp(record.created),

Remove usage here:

"timestamp": datetime.datetime.utcfromtimestamp(record.created),

Also remove usage of datetime.datetime.utcnow() which also appears in the build log

tests/unit/test__http.py::Test_LoggingAPI::test_list_entries_with_limits
  /tmpfs/src/github/python-logging/tests/unit/test__http.py:127: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    NOW = datetime.datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_entries.py::TestLogEntry::test_from_api_repr_w_folder_path
  /tmpfs/src/github/python-logging/tests/unit/test_entries.py:348: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    NOW = datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_entries.py::TestLogEntry::test_from_api_repr_w_loggers_no_logger_match
  /tmpfs/src/github/python-logging/tests/unit/test_entries.py:210: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    NOW = datetime.utcnow().replace(tzinfo=UTC)

tests/unit/test_entries.py::TestLogEntry::test_from_api_repr_w_loggers_w_logger_match
  /tmpfs/src/github/python-logging/tests/unit/test_entries.py:290: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    NOW = datetime.utcnow().replace(tzinfo=UTC)

Remove usage here:

NOW = datetime.datetime.utcnow().replace(tzinfo=UTC)

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/python-logging API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions