Closed PatrikBernhard closed 2 years ago
Yes, that looks like a bug. The isclass
check here is suspicious. How could we have a bound method, t.i. ismethod is True
on a class, t.i. also isclass is True
? 🤔
We can probably just add and not ismodule(mocked_obj)
here; not sure why I don't get the logic here simpler. All we need is to decide if we added the method/function either because it wasn't there in the first place or because we wanted to hide the original implementation which still lives on the class ("prototype") and all the other instances of it.
I released this as a hotfix v1.3.3 Thanks for opening the issue.
When trying to monkeypatch random.randint and then later unstubbing the original method does not get reinstated. Example:
This seems to be because:
not inspect.isclass(self.mocked_obj) and inspect.ismethod(original_method)
in the method restore_method within mocking returns True when it should be False.