Last active
April 12, 2020 17:32
-
-
Save durgaswaroop/4567248b74da6f6a271c418f92ec9b4a to your computer and use it in GitHub Desktop.
Mocking with Pytest-mock articles
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
# application1.py | |
from time import sleep | |
def is_windows(): | |
# This sleep could be some complex operation instead | |
sleep(5) | |
return True | |
def get_operating_system(): | |
return 'Windows' if is_windows() else 'Linux' | |
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
# test_application1a.py | |
from application1 import get_operating_system | |
def test_get_operating_system(mocker): | |
mocker.patch('application1.is_windows', return_value=True) | |
assert get_operating_system() == 'Windows' |
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
# test_application1b.py | |
from application1 import get_operating_system | |
def test_get_operation_system_is_linux(mocker): | |
mocker.patch('application1.is_windows', return_value=False) | |
assert get_operating_system() == 'Linux' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Links to Medium articles: