Log spy actions to file when running tests

This commit is contained in:
shortcutme 2019-12-17 14:33:06 +01:00
parent b138ebc519
commit 6539ca5eb0
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 4 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import logging
class Spy:
def __init__(self, obj, func_name):
self.obj = obj
@ -6,11 +8,12 @@ class Spy:
self.calls = []
def __enter__(self, *args, **kwargs):
logging.debug("Spy started")
def loggedFunc(cls, *args, **kwargs):
call = dict(enumerate(args, 1))
call[0] = cls
call.update(kwargs)
print("Logging", call)
logging.debug("Spy call: %s" % call)
self.calls.append(call)
return self.func_original(cls, *args, **kwargs)
setattr(self.obj, self.__name__, loggedFunc)