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
This commit is contained in:
Tim Burke 2017-04-28 15:56:21 -07:00
parent e1b74c83c4
commit 387ce13aa1

View File

@ -650,7 +650,7 @@ class TestStoragePolicies(unittest.TestCase):
parse_storage_policies(good_conf) parse_storage_policies(good_conf)
mock_driver.assert_called_once() mock_driver.assert_called_once()
mock_driver.reset_mock() 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(""" good_conf = self._conf("""
[storage-policy:0] [storage-policy:0]
@ -665,7 +665,7 @@ class TestStoragePolicies(unittest.TestCase):
parse_storage_policies(good_conf) parse_storage_policies(good_conf)
mock_driver.assert_called_once() mock_driver.assert_called_once()
mock_driver.reset_mock() 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(""" bad_conf = self._conf("""
[storage-policy:0] [storage-policy:0]
@ -685,9 +685,9 @@ class TestStoragePolicies(unittest.TestCase):
for msg in ('known to harm data durability', for msg in ('known to harm data durability',
'Any data in this policy should be migrated', 'Any data in this policy should be migrated',
'https://bugs.launchpad.net/swift/+bug/1639691'): '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 ' 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(""" slightly_less_bad_conf = self._conf("""
[storage-policy:0] [storage-policy:0]
@ -716,7 +716,7 @@ class TestStoragePolicies(unittest.TestCase):
for msg in ('known to harm data durability', for msg in ('known to harm data durability',
'Any data in this policy should be migrated', 'Any data in this policy should be migrated',
'https://bugs.launchpad.net/swift/+bug/1639691'): 'https://bugs.launchpad.net/swift/+bug/1639691'):
self.assertIn(msg, records[0].message) self.assertIn(msg, records[0].msg)
def test_no_default(self): def test_no_default(self):
orig_conf = self._conf(""" orig_conf = self._conf("""