From effafa32304ef06fc5a0f4b3762e8a5a10e81cfc Mon Sep 17 00:00:00 2001 From: zhufl Date: Fri, 19 Jan 2018 13:37:05 +0800 Subject: [PATCH] Get func.__class__.__name__ if no attribute __name__ In call_until_true, if func is wrapped with functools.partial, getattr(func, '__name__') will get "AttributeError: 'functools.partial' object has no attribute '__name__'" Now call_until_true supports args and kwargs that are passed to func, so functools.partial is no longer needed, but it's better for call_until_true to get func.__class__.__name__ if func has not attritube __name__. Change-Id: Icc734e44af925655a31e7dcac04620352093cbeb Closes-Bug: #1744210 --- tempest/lib/common/utils/test_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tempest/lib/common/utils/test_utils.py b/tempest/lib/common/utils/test_utils.py index c2e93ee8a5..2a9f3a92a0 100644 --- a/tempest/lib/common/utils/test_utils.py +++ b/tempest/lib/common/utils/test_utils.py @@ -102,13 +102,13 @@ def call_until_true(func, duration, sleep_for, *args, **kwargs): now = time.time() begin_time = now timeout = now + duration + func_name = getattr(func, '__name__', getattr(func.__class__, '__name__')) while now < timeout: if func(*args, **kwargs): LOG.debug("Call %s returns true in %f seconds", - getattr(func, '__name__'), time.time() - begin_time) + func_name, time.time() - begin_time) return True time.sleep(sleep_for) now = time.time() - LOG.debug("Call %s returns false in %f seconds", - getattr(func, '__name__'), duration) + LOG.debug("Call %s returns false in %f seconds", func_name, duration) return False