diff options
author | Mark McLoughlin <markmc@redhat.com> | 2014-07-13 09:25:33 +0100 |
---|---|---|
committer | Mark McLoughlin <markmc@redhat.com> | 2014-07-13 09:31:28 +0100 |
commit | e5c78bb7b5a574a1fdf86bb3620a0ed0dbe6dc3e (patch) | |
tree | f76af54eb435f3ae8cccb2ebc92bd24cb0b85a36 | |
parent | 569979adfd4237869bb50c7aaa02bc3fd4f0b413 (diff) | |
download | oslo-incubator-e5c78bb7b5a574a1fdf86bb3620a0ed0dbe6dc3e.tar.gz |
log: make set_defaults() tests clean up properly
A call to log.set_defaults() changes the 'default' attribute on the
option definitions statically defined in the log module. Currently, the
tests for this function do not restore the original default values when
the test completes.
This only becomes an issue when the tests are called in a sequence like
this:
- test_change_default_log_level() sets default_log_levels=['foo=bar']
- test_error_notification() subsequently calls log.setup() which tries
to do logger.setLevel('bar') because it's using the bogus default
from the previous test
Change-Id: Id020483049f46b78f834381f37d4ad6c75d49d25
-rw-r--r-- | tests/unit/test_log.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py index 3fa3de65..6439a534 100644 --- a/tests/unit/test_log.py +++ b/tests/unit/test_log.py @@ -533,6 +533,14 @@ class SetDefaultsTestCase(test_base.BaseTestCase): self.conf = self.TestConfigOpts() self.conf.register_opts(log.log_opts) + self._orig_defaults = dict([(o.dest, o.default) + for o in log.log_opts]) + self.addCleanup(self._restore_log_defaults) + + def _restore_log_defaults(self): + for opt in log.log_opts: + opt.default = self._orig_defaults[opt.dest] + def test_default_to_none(self): log.set_defaults(logging_context_format_string=None) self.conf([]) |