From 9dcb47dc556ed792ca4c16ffb3f0c049bd55c971 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 30 Aug 2018 21:15:31 +0200 Subject: [PATCH] Fix utils.reraise for exceptions without args (#210) This is the case for e.g. `bdb.BdbQuit`. --- configurations/utils.py | 2 +- tests/test_main.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/configurations/utils.py b/configurations/utils.py index b74b32a..d9da11b 100644 --- a/configurations/utils.py +++ b/configurations/utils.py @@ -62,7 +62,7 @@ def reraise(exc, prefix=None, suffix=None): suffix = '' elif not (suffix.startswith('(') and suffix.endswith(')')): suffix = '(' + suffix + ')' - exc.args = ('{0} {1} {2}'.format(prefix, exc.args[0], suffix),) + args[1:] + exc.args = ('{0} {1} {2}'.format(prefix, args[0], suffix),) + args[1:] raise diff --git a/tests/test_main.py b/tests/test_main.py index ac3e09b..fe0e6ce 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -118,3 +118,17 @@ class MainTests(TestCase): self.assertIn('setup_2', stdout) self.assertIn('setup_done', stdout) self.assertEqual(proc.returncode, 0) + + def test_utils_reraise(self): + from configurations.utils import reraise + + class CustomException(Exception): + pass + + with self.assertRaises(CustomException) as cm: + try: + raise CustomException + except Exception as exc: + reraise(exc, "Couldn't setup configuration", None) + + self.assertEqual(cm.exception.args, ("Couldn't setup configuration: ",))