remove unnecessary message when running unit test

When we test log related code, we still print the tested log message
into stderr, which is not quite useful for developers, we should
mock those message. Package fixtures.FakeLogger already provides an
option to mock specified logger, so let's use it.

Note: this patch also changes an unnecessary object attribute to local
varible.

Change-Id: I4bc5beaa4eba149f12c58f072fe66163aed8c0c8
Closes-Bug: #1500236
This commit is contained in:
Zhiqiang Fan 2015-09-27 11:13:54 -06:00 committed by ZhiQiang Fan
parent 810176c7ad
commit 4ed9ef91e0

View File

@ -186,8 +186,9 @@ class ClientTest(testtools.TestCase):
'http://foo.com/trove/') 'http://foo.com/trove/')
def test_log_req(self): def test_log_req(self):
self.logger = self.useFixture( logger = self.useFixture(
fixtures.FakeLogger( fixtures.FakeLogger(
name='troveclient.client',
format="%(message)s", format="%(message)s",
level=logging.DEBUG, level=logging.DEBUG,
nuke_handlers=True nuke_handlers=True
@ -207,7 +208,7 @@ class ClientTest(testtools.TestCase):
'data': '{"auth": {"passwordCredentials": ' 'data': '{"auth": {"passwordCredentials": '
'{"password": "password"}}}'}) '{"password": "password"}}}'})
output = self.logger.output.split('\n') output = logger.output.split('\n')
self.assertIn("REQ: curl -i /foo -X GET", output) self.assertIn("REQ: curl -i /foo -X GET", output)
self.assertIn( self.assertIn(