1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 12:06:08 +00:00

utils/exec_control: Fix issue with once_per_instance decorator

Previously the `once_per_instance` used the output of `__repr__` to
identify the class of where the decorated method was called from. For
classes that override this method to produce the same output for
different instances of the same class this caused different instances to
be mistakenly treated as one. Now use the hash of the containing class
instead of the string representation and update the tests to catch this
error.
This commit is contained in:
Marc Bonnici 2018-05-22 16:17:10 +01:00 committed by setrofim
parent bea36cc398
commit 3efff81a5c
2 changed files with 4 additions and 1 deletions

View File

@ -46,6 +46,9 @@ class TestClass(object):
def initilize_once_per_instance(self):
self.count += 1
def __repr__(self):
return '{}: Called={}'.format(self.__class__.__name__, self.called)
class SubClass(TestClass):

View File

@ -57,7 +57,7 @@ def once_per_instance(method):
def wrapper(*args, **kwargs):
if __active_environment is None:
activate_environment('default')
func_id = repr(method.__hash__()) + repr(args[0])
func_id = repr(method.__hash__()) + repr(args[0].__hash__())
if func_id in __environments[__active_environment]:
return
else: