]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
test_misc.py: fix bad assumption about LogRecord fields
authorDan Mick <dmick@redhat.com>
Tue, 16 Nov 2021 01:37:23 +0000 (17:37 -0800)
committerDan Mick <dmick@redhat.com>
Tue, 23 Nov 2021 01:34:41 +0000 (17:34 -0800)
The test was using LogRecord's asctime attribute to calculate a time
difference between two log entries.  Although the attribute is documented
with no caveat, others have run into the problem that it does not exist
on logging.LogRecord unless a formatter with a format string referencing
{asctime} has been used.  Since there's a 'created' time that's more
appropriate for this test anyway, use that instead.

This commit enables updating pytest, because pytest's logging init
code has changed: https://github.com/pytest-dev/pytest/discussions/9324

Signed-off-by: Dan Mick <dmick@redhat.com>
teuthology/test/test_misc.py

index 9b8fe905353cfb2f6cd72c98fb195581ff574674..c765c04c1f48849c949933cee404d87b3f839c66 100644 (file)
@@ -1,5 +1,4 @@
 import argparse
-from datetime import datetime
 
 from unittest.mock import Mock, patch
 from teuthology.orchestra import cluster
@@ -45,9 +44,7 @@ def test_sh_progress(caplog):
     # there must be at least 2 seconds between the log record
     # of the first message and the log record of the second one
     #
-    t1 = datetime.strptime(records[1].asctime.split(',')[0], "%Y-%m-%d %H:%M:%S")
-    t2 = datetime.strptime(records[2].asctime.split(',')[0], "%Y-%m-%d %H:%M:%S")
-    assert (t2 - t1).total_seconds() > 2
+    assert (records[2].created - records[1].created) > 2
 
 
 def test_wait_until_osds_up():