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:
parent
bea36cc398
commit
3efff81a5c
@ -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):
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user