Created
April 2, 2015 09:39
-
-
Save matsjoyce/07f652d6cf4b3e548a13 to your computer and use it in GitHub Desktop.
Result of Override a “private” method in a python module
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
# module.py | |
def _cmd(command, args): | |
# do something nasty | |
print(command, args) | |
def function_to_be_tested(): | |
# do cool things | |
_cmd('rm', '-rf /') | |
return 1 | |
# test.py | |
from mock import patch | |
import module | |
def _cmd_mock(command, args): | |
# do nothing | |
pass | |
@patch('module._cmd', _cmd_mock) | |
def test_function(): | |
assert module.function_to_be_tested() == 1 | |
# result | |
$ python test.py | |
Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment