Include troveclient/compat/tests in testr

All tests should be included in testr.

In test_common.py, the testr command line will be read for parsing,
finally emit error message:
run.py: error: no such option: -t

we should mock the sys.argv in setUp().

The analysis is here
--------------------
troveclient/compat/common.py: CommandsBase
254     def _parse_options(self, parser):
255         opts, args = parser.parse_args()  <-- 1. no arg is passed

/usr/lib/python2.7/optparse.py
1361     def _get_args(self, args):
1362         if args is None:
1363             return sys.argv[1:]  <-- 3. cmdline(testr command) is read
1364         else:
1365             return args[:]

1367     def parse_args(self, args=None, values=None):
...
1381         rargs = self._get_args(args) <-- 2. args is None

Close-Bug #1241845

Change-Id: I092db96d1b6bb31c41e6ba4c5fc9606e3f8ac087
This commit is contained in:
Kui Shi 2013-10-19 15:46:20 +08:00
parent 5af5d6f30d
commit 31a6cde052
4 changed files with 12 additions and 1 deletions

View File

@ -2,7 +2,7 @@
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ ./troveclient/tests $LISTOPT $IDOPTION
${PYTHON:-python} -m subunit.run discover -t ./ ./ $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -4,3 +4,5 @@ sphinx>=1.1.2
testrepository>=0.0.17
testtools>=0.9.32
mock>=1.0
httplib2
lxml>=2.3

View File

View File

@ -147,12 +147,15 @@ class CommandsBaseTest(TestCase):
super(CommandsBaseTest, self).setUp()
self.orig_sys_exit = sys.exit
sys.exit = Mock(return_value=None)
self.orig_sys_argv = sys.argv
sys.argv = ['fakecmd']
parser = common.CliOptions().create_optparser(False)
self.cmd_base = common.CommandsBase(parser)
def tearDown(self):
super(CommandsBaseTest, self).tearDown()
sys.exit = self.orig_sys_exit
sys.argv = self.orig_sys_argv
def test___init__(self):
self.assertNotEqual(None, self.cmd_base)
@ -266,12 +269,15 @@ class AuthTest(TestCase):
super(AuthTest, self).setUp()
self.orig_sys_exit = sys.exit
sys.exit = Mock(return_value=None)
self.orig_sys_argv = sys.argv
sys.argv = ['fakecmd']
self.parser = common.CliOptions().create_optparser(False)
self.auth = common.Auth(self.parser)
def tearDown(self):
super(AuthTest, self).tearDown()
sys.exit = self.orig_sys_exit
sys.argv = self.orig_sys_argv
def test___init__(self):
self.assertEqual(None, self.auth.dbaas)
@ -304,10 +310,13 @@ class AuthedCommandsBaseTest(TestCase):
super(AuthedCommandsBaseTest, self).setUp()
self.orig_sys_exit = sys.exit
sys.exit = Mock(return_value=None)
self.orig_sys_argv = sys.argv
sys.argv = ['fakecmd']
def tearDown(self):
super(AuthedCommandsBaseTest, self).tearDown()
sys.exit = self.orig_sys_exit
self.orig_sys_argv = sys.argv
def test___init__(self):
parser = common.CliOptions().create_optparser(False)