From 021749a734265d5f19cab156ccddb8e3d3e121a4 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Tue, 5 Nov 2019 11:25:30 -0500 Subject: [PATCH] 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 --- nova/tests/functional/api_samples_test_base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nova/tests/functional/api_samples_test_base.py b/nova/tests/functional/api_samples_test_base.py index d9bd8a215ceb..c2e144235a2c 100644 --- a/nova/tests/functional/api_samples_test_base.py +++ b/nova/tests/functional/api_samples_test_base.py @@ -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'