Register oslo.log's config options in tests

When running tests with testr oslo.log's config options are always
registered even if you're only running one test. When you wish to debug
into your tests and use python -m testtools.run these options will not
be registered.

Closes-bug: 1433785
Change-Id: Ie3426cee8cd3f6f1222529160d39b281af5ce317
This commit is contained in:
Ian Cordasco 2015-03-18 15:54:38 -05:00
parent bcc7721550
commit 7c419a60b1
1 changed files with 14 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import subprocess
import fixtures
from oslo_config import cfg
from oslo_log import log
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from oslotest import moxstubout
@ -43,6 +44,19 @@ from glance.db.sqlalchemy import api as db_api
from glance.db.sqlalchemy import models as db_models
CONF = cfg.CONF
try:
CONF.debug
except cfg.NoSuchOptError:
# NOTE(sigmavirus24): If we run the entire test suite, the logging options
# will be registered appropriately and we do not need to re-register them.
# However, when we run a test in isolation (or use --debug), those options
# will not be registered for us. In order for a test in a class that
# inherits from BaseTestCase to even run, we will need to register them
# ourselves. BaseTestCase.config will set the debug level if something
# calls self.config(debug=True) so we need these options registered
# appropriately.
# See bug 1433785 for more details.
log.register_options(CONF)
class BaseTestCase(testtools.TestCase):