Last active
July 5, 2018 19:02
-
-
Save ikonst/9d1f60ec9585bcf38ad792299028df65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(): | |
message = 'foo' | |
def bar(self): | |
print('bar') | |
from unittest.mock import patch | |
def baz(self): | |
print(self.message) | |
@patch.object(Foo, 'bar', autospec=True, side_effect=baz) | |
# ^^^^^^^^^^^^^ | |
# this is essential | |
def test(mock_bar): | |
foo = Foo() | |
foo.bar() | |
assert mock_bar.call_count == 1 | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment