From f28446e970258fac0979ddd0f6d436cc779cb488 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 4 Sep 2013 10:44:39 +0200 Subject: [PATCH] Fix problem with mocking tasks It was previously impossible to stub out a task with mox, because when the TaskRunner attempted to get the __name__ attribute it prompted an assertion in the mock. Using hasattr() instead of getattr() eliminates this issue. Change-Id: I3757a77daf59cbb3c0a8b60329d490a89e7ec1d3 --- heat/engine/scheduler.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index 20e2e7ed..4bc691b1 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -36,11 +36,10 @@ def task_description(task): Return a human-readable string description of a task suitable for logging the status of the task. """ - name = getattr(task, '__name__', None) + name = task.__name__ if hasattr(task, '__name__') else None if isinstance(task, types.MethodType): - obj = getattr(task, '__self__', None) - if name is not None and obj is not None: - return '%s from %s' % (name, obj) + if name is not None and hasattr(task, '__self__'): + return '%s from %s' % (name, task.__self__) elif isinstance(task, types.FunctionType): if name is not None: return str(name) -- 2.45.2