From 9f37e22c4791de6e0788742fed4f657c626b98d5 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Tue, 13 Aug 2013 18:09:55 +0200 Subject: [PATCH] Remove the mongo auth warning during tests pymongo print a warning on each mongodb connection because the url used in tests don't have credentials, since all mongodb tests are running in a different mongodb databases, this print many annoying line like this one: UserWarning: database name or authSource in URI is being ignored. If you wish to authenticate to ceilometer_90d94586954643e8811d5ecc6bacf912, you must provide a username and password. This change suppress this line during testing. Fixes bug #1210674 Change-Id: Iecabca621c2fbaf15e644f2fca66b4e3b5bd04e7 --- ceilometer/tests/db.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ceilometer/tests/db.py b/ceilometer/tests/db.py index df117e008..19b2a18b4 100644 --- a/ceilometer/tests/db.py +++ b/ceilometer/tests/db.py @@ -21,6 +21,7 @@ """Base classes for API tests.""" import os import uuid +import warnings from oslo.config import cfg @@ -33,10 +34,15 @@ class TestBase(test_base.TestCase): super(TestBase, self).setUp() cfg.CONF.set_override('connection', str(self.database_connection), group='database') - try: - self.conn = storage.get_connection(cfg.CONF) - except storage.StorageBadVersion as e: - self.skipTest(str(e)) + + with warnings.catch_warnings(): + warnings.filterwarnings( + action='ignore', + message='.*you must provide a username and password.*') + try: + self.conn = storage.get_connection(cfg.CONF) + except storage.StorageBadVersion as e: + self.skipTest(str(e)) self.conn.upgrade() def tearDown(self):