mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Make python tests use timezone, py3.12 deprecated tz-less utcnow()
Python upstream is trying to eliminate tz-naive date functions that imply anything to do with a timezone, even UTC. They have deprecated datetime.datetime.utcnow() in Python 3.12 and thus running tests emits many warnings for us. We switch to instantiate datetime objects taht are intended to reflect UTC to have a timezone, or if we instantiate naive ones and then later convert, we do the full conversion. After the changes, the tests still work on Python 3.9, but now also on Python 3.12 without warnings. See PR description for #632 for more details. Signed-off-by: Scott Mcdermott <scott@smemsh.net>
This commit is contained in:
parent
05b72bba6f
commit
05724a9d21
22 changed files with 220 additions and 207 deletions
|
@ -29,7 +29,8 @@
|
|||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from dateutil import tz
|
||||
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
@ -57,7 +58,7 @@ class TestLengthen(TestCase):
|
|||
def test_lengthen_synthetic_interval(self):
|
||||
"""Lengthen a synthetic interval."""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
now_utc = now.replace(tzinfo=tz.tzlocal()).astimezone(timezone.utc)
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue