[TIP] How do I mock future instances of a class?
yonix85 at gmail.com
Wed May 25 03:39:20 PDT 2011
Sorry for spamming with mock questions the last few days :)
Just doing some massive testing for complicated code.
I know that when I patch a specific method:
@patch("package.MyClassName.my_method", new = Mock(return_value="xyz"))
Even new instances of MyClass will return "xyz" as expected.
However, when I try:
def test_something(self, my_mock):
my_mock.my_method.return_value = "xyz"
When in code I run:
I get a new different Mock and not "xyz" as I would wish.
Now, it kinda makes sense to me, but I would like to know if there's a way
Couldn't really achieve this by mocking __init__ (or maybe I did it wrong?)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python