Skip to content

Commit

Permalink
Fix DeprecationWarning with newer Python versions
Browse files Browse the repository at this point in the history
Using pytest-logger 1.1.0 with Python 3.12 results in the following
DeprecationWarning:

  /Users/xxx/.venv/lib/python3.12/site-packages/pytest_logger/plugin.py:310: 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).
    dt = datetime.datetime.utcfromtimestamp(ct)
  • Loading branch information
lcosmin committed Mar 7, 2024
1 parent 322b8b9 commit 53628f2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pytest_logger/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def __init__(self):

def formatTime(self, record, datefmt=None):
ct = record.created - self._start
dt = datetime.datetime.utcfromtimestamp(ct)
dt = datetime.datetime.fromtimestamp(ct, tz=datetime.timezone.utc)
return dt.strftime("%M:%S.%f")[:-3] # omit useconds, leave mseconds

def format(self, record):
Expand Down

0 comments on commit 53628f2

Please sign in to comment.