I am trying to fix a class method using mock as described in the documentation . The Mock object itself works fine, but its methods are not executed: for example, their attributes, such as call_count , are not updated, even if the method_calls attribute of the class Mock object. More importantly, their return_value attribute return_value ignored:
class Lib: """In my actual program, a module that I import""" def method(self): return "real" class User: """The class I want to test""" def run(self): l = Lib() return l.method() with patch("__main__.Lib") as mock:
What am I doing wrong here?
EDIT: passing the Mock class through the constructor does not work either, so this is not related to the patch function.
python unit-testing mocking
Erik
source share