Skip to content

Instantly share code, notes, and snippets.

@gbalbuena
Created May 20, 2020 01:14
Show Gist options
  • Save gbalbuena/4f970a04e0f8ec1a30edc700579fd34b to your computer and use it in GitHub Desktop.
Save gbalbuena/4f970a04e0f8ec1a30edc700579fd34b to your computer and use it in GitHub Desktop.
pytest mock example
pytest
pytest-mock
import pytest
import thing
@pytest.fixture()
def event():
return {}
def test_exposure_simple_function(event):
assert thing.simple_function() == "You have called simple_function"
def test_mock(mocker):
mocker.patch('exposure.simple_function')
thing.simple_function.return_value = "You have mocked simple_function"
assert thing.simple_function() == "You have mocked simple_function"
def simple_function():
return "You have called simple_function"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment