Fix unit tests when they are run with OS_DEBUG=True

This patch fix test_default_logging test.
The test validates that we have two logging handlers:
1 x to display default messages (info, error, warnings...)
1 x to redirect debug messages to null and so don't display them.

However, if OS_DEBUG=True is set in a shell session, then the test is
run and fails. Because, in debug mode, we should have only one handler
to display all messages. (look at comments for more details and
 test_debug_logging test).

To fix the test, we explicitly set OS_DEBUG=0 when running
test_default_logging, so it will ensure we have two handlers whatever
OS_DEBUG value.

Co-authored-by: Rene Ribaud <rribaud@redhat.com>
Closes-Bug: #1964497

Change-Id: I7c0151d988c538dd2d083aab4b3e18ddb8151045
This commit is contained in:
Artom Lifshitz 2022-03-10 10:53:13 -05:00 committed by René Ribaud
parent f41be79f1a
commit 84c6d05ac3
1 changed files with 14 additions and 0 deletions

View File

@ -51,6 +51,20 @@ CONF = cfg.CONF
class TestLogging(testtools.TestCase):
def test_default_logging(self):
# This test validates that in default logging mode,
# we have two logging handlers:
# 1 x to display default messages (info, error, warnings...)
# 1 x to redirect debug messages to null and so don't display them.
# However, if OS_DEBUG=True is set in a shell session, then the test is
# run and fails. Because, in debug mode, we should have
# only one handler to display all messages.
# Here, we explicitly set OS_DEBUG=0.
# So it will ensure we have two handlers whatever
# OS_DEBUG value set in the user shell.
self.useFixture(fx.EnvironmentVariable('OS_DEBUG', '0'))
stdlog = self.useFixture(fixtures.StandardLogging())
root = logging.getLogger()
# there should be a null handler as well at DEBUG