From 387ce13aa15ada80a40b93a0d9e12d2be0ff927e Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 28 Apr 2017 15:56:21 -0700 Subject: [PATCH] Use LogRecord.msg instead of LogRecord.message in tests From the docs for LogRecord.message [1], > This is set when Formatter.format() is invoked. Apparently we may find ourselves in a situation [2] where that never happens? Really weird that it failed *midway* through the test though; maybe some concurrent test removed all formatters? ERROR: test_known_bad_ec_config (test.unit.common.test_storage_policy.TestStoragePolicies) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../mock/mock.py", line 1305, in patched return func(*args, **keywargs) File ".../test/unit/common/test_storage_policy.py", line 688, in test_known_bad_ec_config self.assertIn(msg, records[0].message) AttributeError: 'LogRecord' object has no attribute 'message' [1] https://docs.python.org/2/library/logging.html#logrecord-attributes [2] http://logs.openstack.org/59/460359/1/check/gate-swift-tox-xfs-tmp-py27-ubuntu-xenial/5ecc2cb/console.html#_2017-04-27_01_06_43_346096 Change-Id: I8f5ac0ec1195a233f14edc0126de1d1cea7a6e2f --- test/unit/common/test_storage_policy.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/common/test_storage_policy.py b/test/unit/common/test_storage_policy.py index c755ec612a..cfa7baaf26 100644 --- a/test/unit/common/test_storage_policy.py +++ b/test/unit/common/test_storage_policy.py @@ -650,7 +650,7 @@ class TestStoragePolicies(unittest.TestCase): parse_storage_policies(good_conf) mock_driver.assert_called_once() mock_driver.reset_mock() - self.assertFalse([(r.levelname, r.message) for r in records]) + self.assertFalse([(r.levelname, r.msg) for r in records]) good_conf = self._conf(""" [storage-policy:0] @@ -665,7 +665,7 @@ class TestStoragePolicies(unittest.TestCase): parse_storage_policies(good_conf) mock_driver.assert_called_once() mock_driver.reset_mock() - self.assertFalse([(r.levelname, r.message) for r in records]) + self.assertFalse([(r.levelname, r.msg) for r in records]) bad_conf = self._conf(""" [storage-policy:0] @@ -685,9 +685,9 @@ class TestStoragePolicies(unittest.TestCase): for msg in ('known to harm data durability', 'Any data in this policy should be migrated', 'https://bugs.launchpad.net/swift/+bug/1639691'): - self.assertIn(msg, records[0].message) + self.assertIn(msg, records[0].msg) self.assertIn('In a future release, this will prevent services from ' - 'starting', records[1].message) + 'starting', records[1].msg) slightly_less_bad_conf = self._conf(""" [storage-policy:0] @@ -716,7 +716,7 @@ class TestStoragePolicies(unittest.TestCase): for msg in ('known to harm data durability', 'Any data in this policy should be migrated', 'https://bugs.launchpad.net/swift/+bug/1639691'): - self.assertIn(msg, records[0].message) + self.assertIn(msg, records[0].msg) def test_no_default(self): orig_conf = self._conf("""