Make test logging setup fixture disable future setup

Our logging fixture sets up logging in a way that we need to capture
things during tests. However, some of our tests do things like call
back into main functions, which then call logging setup again, and
unwind everything we're doing (including debug message testing).

This patches out oslo_log setup after the fixture runs, thus ignoring
calls to it in the future.

This change originally implemented in Nova with commit
dc2f4f88ac8d7bcf904908b4683522cd6839ba70.

Closes-bug: #1728640
Change-Id: I3f95fd3b83d6b5c5801d3a16a3e73623ed49da29
This commit is contained in:
Sean McGinnis 2017-10-31 15:05:12 -05:00 committed by Sean McGinnis
parent a11dcdb0f7
commit 57321ad60c
1 changed files with 11 additions and 0 deletions

View File

@ -99,3 +99,14 @@ class StandardLogging(fixtures.Fixture):
# Don't log every single DB migration step
std_logging.getLogger(
'migrate.versioning.api').setLevel(std_logging.WARNING)
# At times we end up calling back into main() functions in
# testing. This has the possibility of calling logging.setup
# again, which completely unwinds the logging capture we've
# created here. Once we've setup the logging in the way we want,
# disable the ability for the test to change this.
def fake_logging_setup(*args):
pass
self.useFixture(
fixtures.MonkeyPatch('oslo_log.log.setup', fake_logging_setup))