Improve error info in assertEmpty and assertNotEmpty

When assertEmpty fails, it will print:
        raise mismatch_error
    MismatchError: 0 != 5

this is to improve the error info as:
        raise mismatch_error
    MismatchError: 0 != 1: list is not empty: [u'1b95a8ea7e124a76bfadf6ce1906aa27']

and when assertNotEmpty fails, it will print:
        raise self.failureException(msg)
    AssertionError: 0 not greater than 0

this is to improve the error info as:
        raise self.failureException(msg)
    AssertionError: list is empty.

Change-Id: Icdf69b596fa135387721c49df164a68799ab9a70
This commit is contained in:
zhufl 2017-03-03 15:20:10 +08:00
parent 9ca8ef195a
commit 92ade4b8b1
1 changed files with 4 additions and 0 deletions

View File

@ -643,7 +643,11 @@ class BaseTestCase(testtools.testcase.WithAttributes,
cred_provider, networks_client, CONF.compute.fixed_network_name)
def assertEmpty(self, list, msg=None):
if msg is None:
msg = "list is not empty: %s" % list
self.assertEqual(0, len(list), msg)
def assertNotEmpty(self, list, msg=None):
if msg is None:
msg = "list is empty."
self.assertGreater(len(list), 0, msg)