diff --git a/test/__init__.py b/test/__init__.py index 98d0b42ecd..72dff139bf 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -18,6 +18,20 @@ import sys import os +try: + from unittest.util import safe_repr +except ImportError: + # Probably py26 + _MAX_LENGTH = 80 + + def safe_repr(obj, short=False): + try: + result = repr(obj) + except Exception: + result = object.__repr__(obj) + if not short or len(result) < _MAX_LENGTH: + return result + return result[:_MAX_LENGTH] + ' [truncated]...' # make unittests pass on all locale import swift diff --git a/test/functional/swift_test_client.py b/test/functional/swift_test_client.py index f9e031b67b..061497a0b7 100644 --- a/test/functional/swift_test_client.py +++ b/test/functional/swift_test_client.py @@ -28,6 +28,8 @@ from nose import SkipTest from xml.dom import minidom from swiftclient import get_auth +from test import safe_repr + class AuthenticationFailed(Exception): pass @@ -216,18 +218,22 @@ class Connection(object): self.response = None try_count = 0 + fail_messages = [] while try_count < 5: try_count += 1 try: self.response = try_request() - except httplib.HTTPException: + except httplib.HTTPException as e: + fail_messages.append(safe_repr(e)) continue if self.response.status == 401: + fail_messages.append("Response 401") self.authenticate() continue elif self.response.status == 503: + fail_messages.append("Response 503") if try_count != 5: time.sleep(5) continue @@ -237,7 +243,11 @@ class Connection(object): if self.response: return self.response.status - raise RequestError('Unable to complete http request') + request = "{method} {path} headers: {headers} data: {data}".format( + method=method, path=path, headers=headers, data=data) + raise RequestError('Unable to complete http request: %s. ' + 'Attempts: %s, Failures: %s' % + (request, len(fail_messages), fail_messages)) def put_start(self, path, hdrs={}, parms={}, cfg={}, chunked=False): self.http_connect() diff --git a/test/unit/common/test_constraints.py b/test/unit/common/test_constraints.py index 80f5ff7736..9d62b5968e 100644 --- a/test/unit/common/test_constraints.py +++ b/test/unit/common/test_constraints.py @@ -14,23 +14,9 @@ # limitations under the License. import unittest -try: - from unittest.util import safe_repr -except ImportError: - # Probably py26 - _MAX_LENGTH = 80 - - def safe_repr(obj, short=False): - try: - result = repr(obj) - except Exception: - result = object.__repr__(obj) - if not short or len(result) < _MAX_LENGTH: - return result - return result[:_MAX_LENGTH] + ' [truncated]...' - import mock +from test import safe_repr from test.unit import MockTrue from swift.common.swob import HTTPBadRequest, Request