From a9b144cbdf22590e3b0c10607eea7ed15aca75a6 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 29 Jul 2010 15:18:47 +0200 Subject: [PATCH] Ensure assertions are evaluated in tests A lot of assertions are used in Ganeti's code. Some unittests even check whether AssertionError is raised in some cases. Explicitely ensuring assertions are evaluated makes sure those tests don't fail and assertions are checked. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- test/testutils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/testutils.py b/test/testutils.py index fd95c76dc..fd4655a98 100644 --- a/test/testutils.py +++ b/test/testutils.py @@ -45,6 +45,19 @@ class GanetiTestProgram(unittest.TestProgram): sys.stderr.write("Running %s\n" % self.progName) sys.stderr.flush() + # Ensure assertions will be evaluated + if not __debug__: + raise Exception("Not running in debug mode, assertions would not be" + " evaluated") + + # Check again, this time with a real assertion + try: + assert False + except AssertionError: + pass + else: + raise Exception("Assertion not evaluated") + return unittest.TestProgram.runTests(self) -- GitLab