Gibt es eine Möglichkeit, dies mit Python Unittest zu tun? Ich habe die Dokumentation zum Unittest-Attribut „mock.wraps“ gelesen, aber es fällt mir immer noch schwer, die Verwendung des Attributs zu verstehen.
Code: Select all
# module 1
def pass_wrap(*args):
print(args)
class OriginalClass():
def foo(self, a, b):
return_val = self.bar(a,b)
is_validated = self.baz(return_val)
return is_validated
def bar(self, a, b):
return a + b
def baz(self, result):
return result > 2
Code: Select all
# testing file
from module_1 import OriginalClass
def wrapper(*args):
print(args) # prints the calling args
class Test():
@patch("module_1.OriginalClass.bar", wraps=pass_wrap)
def test_01(self, mock):
# how do I get the return result of bar?
OriginalClass.foo(1,2)
args, kwargs = mock.call_args
print(args, kwargs)
Mobile version