From 3528e90b0cf8c68e72202c32fada445d39ca13e0 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Wed, 14 Jan 2015 11:22:50 +0000 Subject: Fix test_cli exit code assertion Currently we ignore the actual return code from the main() function, due to the try/catch, which isn't appropriate where we're directly calling the function. Instead assert the return value directly, which will catch failures where main returns a non-zero status. Change-Id: Ic92ca243230f732201f30cc63be5101f70c206bb --- os_net_config/tests/test_cli.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/os_net_config/tests/test_cli.py b/os_net_config/tests/test_cli.py index 609f0ab..908dd7e 100644 --- a/os_net_config/tests/test_cli.py +++ b/os_net_config/tests/test_cli.py @@ -30,20 +30,18 @@ class TestCli(base.TestCase): def run_cli(self, argstr, exitcodes=(0,)): orig = sys.stdout orig_stderr = sys.stderr - try: - sys.stdout = six.StringIO() - sys.stderr = six.StringIO() - cli.main(argstr.split()) - except SystemExit: - exc_type, exc_value, exc_traceback = sys.exc_info() - self.assertIn(exc_value.code, exitcodes) - finally: - stdout = sys.stdout.getvalue() - sys.stdout.close() - sys.stdout = orig - stderr = sys.stderr.getvalue() - sys.stderr.close() - sys.stderr = orig_stderr + + sys.stdout = six.StringIO() + sys.stderr = six.StringIO() + ret = cli.main(argstr.split()) + self.assertIn(ret, exitcodes) + + stdout = sys.stdout.getvalue() + sys.stdout.close() + sys.stdout = orig + stderr = sys.stderr.getvalue() + sys.stderr.close() + sys.stderr = orig_stderr return (stdout, stderr) def test_bond_noop_output(self): -- cgit 1.2.3-korg