From b1e3753fdfea638ec8c82cddd910a0b3e0f627a6 Mon Sep 17 00:00:00 2001 From: Kui Shi Date: Tue, 8 Oct 2013 16:57:43 +0800 Subject: [PATCH] Align mocking pattern for test case Mock sys.stderr/sys.stdout with mock.patch() In novaclient/tests/test_shell.py, ShellTest.shell(), it is another case that should be aligned. But it may induce test error if changed. So, let's keep it as is. Close-Bug #1237093 Change-Id: I8908dc1593dbbbaf2813cc8fb034be32972140a0 --- novaclient/tests/v1_1/test_shell.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index 430eb99c5..8a1ade65c 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -644,19 +644,12 @@ class ShellTest(utils.TestCase): self.run_command('image-meta 1 delete test_key=test_value') self.assert_called('DELETE', '/images/1/metadata/test_key') + @mock.patch('sys.stdout', six.StringIO()) + @mock.patch('sys.stderr', six.StringIO()) def test_image_meta_bad_action(self): - tmp = six.StringIO() - - # Suppress stdout and stderr - (stdout, stderr) = (sys.stdout, sys.stderr) - (sys.stdout, sys.stderr) = (tmp, tmp) - self.assertRaises(SystemExit, self.run_command, 'image-meta 1 BAD_ACTION test_key=test_value') - # Put stdout and stderr back - sys.stdout, sys.stderr = (stdout, stderr) - def test_image_list(self): self.run_command('image-list') self.assert_called('GET', '/images/detail')