Provide a better error when _verify_response hits a TypeError
While trying to fix some functional API samples tests that were failing I was getting a TypeError which gave me basically no information about the field in the template that didn't match the response, e.g.: TypeError: expected string or bytes-like object This change fixes that so we get something much more useful about the incorrect field when verifying the response fails, e.g.: nova.tests.functional.api_samples_test_base.NoMatch: Failed to match Template to Response: Values do not match: Template: ^foo$ Response: None Error: expected string or bytes-like object Template: { 'volumeAttachment': { 'delete_on_termination': True, 'device': '%(device)s', 'id': '%(volume_id)s', 'serverId': '%(uuid)s', 'tag': '%(tag)s', 'volumeId': '%(volume_id)s'}} Response: { 'volumeAttachment': { 'delete_on_termination': True, 'device': '/dev/sdb', 'id': 'a07f71dc-8151-4e7d-a0cc-cd24a3f11113', 'serverId': '80355020-98a0-4a84-bd9d-01ac700ac3a7', 'tag': None, 'volumeId': 'a07f71dc-8151-4e7d-a0cc-cd24a3f11113'}} Change-Id: I7538affa296562bedeaedb07f878456cf78ca132
This commit is contained in:
@@ -245,7 +245,15 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
||||
|
||||
expected = expected % self.subs
|
||||
expected = '^%s$' % expected
|
||||
match = re.match(expected, result)
|
||||
try:
|
||||
match = re.match(expected, result)
|
||||
except TypeError as e:
|
||||
raise NoMatch(
|
||||
'Values do not match:\n'
|
||||
'Template: %(expected)s\n%(result_str)s: %(result)s\n'
|
||||
'Error: %(error)s' %
|
||||
{'expected': expected, 'result_str': result_str,
|
||||
'result': result, 'error': e})
|
||||
if not match:
|
||||
raise NoMatch(
|
||||
'Values do not match:\n'
|
||||
|
Reference in New Issue
Block a user