Suppress expected help messages caused by wrong CLI inputs
There are negative tests for the NSX gateway feature. This patch introduces the ability to suppress the warning messages caused by running commands with wrong parameters. This keeps the console output clean of spurious errors. Change-Id: Idc78442969b3e06ecef9999a7edfc6544ed3a376 Closes-bug: #1311348
This commit is contained in:
parent
f6eba87aa1
commit
91bea9479d
|
@ -16,8 +16,11 @@
|
|||
|
||||
import urllib
|
||||
|
||||
import contextlib
|
||||
import cStringIO
|
||||
import fixtures
|
||||
import mox
|
||||
import sys
|
||||
import testtools
|
||||
|
||||
from neutronclient.common import constants
|
||||
|
@ -32,6 +35,17 @@ TOKEN = 'testtoken'
|
|||
ENDURL = 'localurl'
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def capture_std_streams():
|
||||
fake_stdout, fake_stderr = cStringIO.StringIO(), cStringIO.StringIO()
|
||||
stdout, stderr = sys.stdout, sys.stderr
|
||||
try:
|
||||
sys.stdout, sys.stderr = fake_stdout, fake_stderr
|
||||
yield fake_stdout, fake_stderr
|
||||
finally:
|
||||
sys.stdout, sys.stderr = stdout, stderr
|
||||
|
||||
|
||||
class FakeStdout:
|
||||
|
||||
def __init__(self):
|
||||
|
|
|
@ -146,10 +146,11 @@ class CLITestV20NetworkGatewayJSON(test_cli20.CLITestV20Base):
|
|||
args.extend(['--client-certificate', client_certificate_file])
|
||||
args.append(name)
|
||||
if must_raise:
|
||||
self.assertRaises(
|
||||
SystemExit, self._test_create_resource,
|
||||
self.dev_resource, cmd, name, myid, args,
|
||||
position_names, position_values, extra_body=extra_body)
|
||||
with test_cli20.capture_std_streams():
|
||||
self.assertRaises(
|
||||
SystemExit, self._test_create_resource,
|
||||
self.dev_resource, cmd, name, myid, args,
|
||||
position_names, position_values, extra_body=extra_body)
|
||||
else:
|
||||
self._test_create_resource(
|
||||
self.dev_resource, cmd, name, myid, args,
|
||||
|
@ -213,10 +214,11 @@ class CLITestV20NetworkGatewayJSON(test_cli20.CLITestV20Base):
|
|||
args.extend(['--client-certificate-file',
|
||||
client_certificate_file])
|
||||
if must_raise:
|
||||
self.assertRaises(
|
||||
SystemExit, self._test_update_resource,
|
||||
self.dev_resource, cmd, myid, args,
|
||||
extrafields=extra_body)
|
||||
with test_cli20.capture_std_streams():
|
||||
self.assertRaises(
|
||||
SystemExit, self._test_update_resource,
|
||||
self.dev_resource, cmd, myid, args,
|
||||
extrafields=extra_body)
|
||||
else:
|
||||
self._test_update_resource(
|
||||
self.dev_resource, cmd, myid, args,
|
||||
|
|
Loading…
Reference in New Issue