Created
May 20, 2020 01:14
-
-
Save gbalbuena/4f970a04e0f8ec1a30edc700579fd34b to your computer and use it in GitHub Desktop.
pytest mock example
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
pytest | |
pytest-mock |
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
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" |
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
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