From: Sage Weil Date: Wed, 27 Jan 2021 21:44:21 +0000 (-0600) Subject: python-common: fix test_datetime_to_str_2 on non-UTC hosts X-Git-Tag: v17.1.0~3135^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=78aca4db249c409d0cd5a24bfae81e55cf930bc3;p=ceph.git python-common: fix test_datetime_to_str_2 on non-UTC hosts The old test parsed to a datetime without a tz, which was interpreted as the local time zone when rendering back to a string. Specify that it's a UTC datetime so that behavior is consistent regardless of the test host timezone. Signed-off-by: Sage Weil --- diff --git a/src/python-common/ceph/tests/test_datetime.py b/src/python-common/ceph/tests/test_datetime.py index a5c6ec001517..d03a829301f5 100644 --- a/src/python-common/ceph/tests/test_datetime.py +++ b/src/python-common/ceph/tests/test_datetime.py @@ -11,8 +11,11 @@ def test_datetime_to_str_1(): def test_datetime_to_str_2(): - dt = datetime.datetime.strptime('2019-04-24T17:06:53.039991', - '%Y-%m-%dT%H:%M:%S.%f') + # note: tz isn't specified in the string, so explicitly store this as UTC + dt = datetime.datetime.strptime( + '2019-04-24T17:06:53.039991', + '%Y-%m-%dT%H:%M:%S.%f' + ).replace(tzinfo=datetime.timezone.utc) assert datetime_to_str(dt) == '2019-04-24T17:06:53.039991Z'