diff options
author | Steven Hardy <shardy@redhat.com> | 2015-01-14 11:22:50 +0000 |
---|---|---|
committer | Steven Hardy <shardy@redhat.com> | 2015-01-14 11:51:48 +0000 |
commit | 3528e90b0cf8c68e72202c32fada445d39ca13e0 (patch) | |
tree | 3e5e82d5614d6a045c80283881dc55772709ca6c | |
parent | cd7408e41e16fe06038b6529e7206483f67061a3 (diff) |
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
-rw-r--r-- | os_net_config/tests/test_cli.py | 26 |
1 files 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): |