From 0d454882353ae82ccf4d20f792b042994a78500a Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Fri, 22 Sep 2023 15:42:21 +0100 Subject: [PATCH] Remove use of deprecated `datetime.datetime` methods The methods `datetime.datetime.utc` and `.utcfromtimestamp` were marked deprecated in Python 3.12 in favour of `now(tz=datetime.timezone.utc)` and `fromtimestamp(tz=datetime.timezone.utc)` [1]. [1]: https://github.com/python/cpython/issues/103857 --- NEWS | 3 +++ python/subunit/test_results.py | 2 +- python/subunit/v2.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 888dd24..01dc83d 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ subunit release notes NEXT (In development) --------------------- +* Removed use of deprecated "utc" and "utcfromtimestamp" + methods of "datetime.datetime". (Jake Lishman) + 1.4.3 (2023-09-17) --------------------- diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py index 618bd82..6690fb1 100644 --- a/python/subunit/test_results.py +++ b/python/subunit/test_results.py @@ -192,7 +192,7 @@ def _before_event(self): time = self._time if time is not None: return - time = datetime.datetime.utcnow().replace(tzinfo=iso8601.UTC) + time = datetime.datetime.now(tz=iso8601.UTC) self.decorated.time(time) def progress(self, offset, whence): diff --git a/python/subunit/v2.py b/python/subunit/v2.py index 6920ae2..32c11da 100644 --- a/python/subunit/v2.py +++ b/python/subunit/v2.py @@ -46,7 +46,7 @@ FLAG_MIME_TYPE = 0x0020 FLAG_EOF = 0x0010 FLAG_FILE_CONTENT = 0x0040 -EPOCH = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=iso8601.UTC) +EPOCH = datetime.datetime.fromtimestamp(0, tz=iso8601.UTC) NUL_ELEMENT = b'\0'[0] # Contains True for types for which 'nul in thing' falsely returns false. _nul_test_broken = {}