Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to mock an external API with pytest_mock
class Api():
def persons(self):
return ['hek2mgl', 'lgm2keh']
class App(Api):
def hello_messages(self):
msg = []
for p in self.persons():
msg += ["Hello {}".format(p)]
return msg
def test_app(mocker):
mocker.patch('{}.Api.persons'.format(__name__),
return_value=['a','b'])
a = App()
assert a.hello_messages() == ([
"Hello a",
"Hello b"
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.