From 5a0e63af1eafe70c0df3c4319c55ce6d297e3580 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 21 Oct 2015 11:53:30 -0700 Subject: [PATCH] Workaround seeming bug in python-2.6's sys.exit() --- .../units/module_utils/basic/test_exit_json.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/units/module_utils/basic/test_exit_json.py b/test/units/module_utils/basic/test_exit_json.py index 498a53e53d4..66610ec3ed3 100644 --- a/test/units/module_utils/basic/test_exit_json.py +++ b/test/units/module_utils/basic/test_exit_json.py @@ -50,21 +50,33 @@ class TestAnsibleModuleExitJson(unittest.TestCase): def test_exit_json_no_args_exits(self): with self.assertRaises(SystemExit) as ctx: self.module.exit_json() - self.assertEquals(ctx.exception.code, 0) + if isinstance(ctx.exception, int): + # Python2.6... why does sys.exit behave this way? + self.assertEquals(ctx.exception, 0) + else: + self.assertEquals(ctx.exception.code, 0) return_val = json.loads(self.fake_stream.getvalue()) self.assertEquals(return_val, dict(changed=False)) def test_exit_json_args_exits(self): with self.assertRaises(SystemExit) as ctx: self.module.exit_json(msg='message') - self.assertEquals(ctx.exception.code, 0) + if isinstance(ctx.exception, int): + # Python2.6... why does sys.exit behave this way? + self.assertEquals(ctx.exception, 0) + else: + self.assertEquals(ctx.exception.code, 0) return_val = json.loads(self.fake_stream.getvalue()) self.assertEquals(return_val, dict(msg="message", changed=False)) def test_fail_json_exits(self): with self.assertRaises(SystemExit) as ctx: self.module.fail_json(msg='message') - self.assertEquals(ctx.exception.code, 1) + if isinstance(ctx.exception, int): + # Python2.6... why does sys.exit behave this way? + self.assertEquals(ctx.exception, 1) + else: + self.assertEquals(ctx.exception.code, 1) return_val = json.loads(self.fake_stream.getvalue()) self.assertEquals(return_val, dict(msg="message", failed=True))