From 84c6d05ac343029cf151c35d4696cee0dc74f2c9 Mon Sep 17 00:00:00 2001 From: Artom Lifshitz Date: Thu, 10 Mar 2022 10:53:13 -0500 Subject: [PATCH] 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 Closes-Bug: #1964497 Change-Id: I7c0151d988c538dd2d083aab4b3e18ddb8151045 --- nova/tests/unit/test_fixtures.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nova/tests/unit/test_fixtures.py b/nova/tests/unit/test_fixtures.py index 22b278771a3a..5dbcd6d57ade 100644 --- a/nova/tests/unit/test_fixtures.py +++ b/nova/tests/unit/test_fixtures.py @@ -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