Created
December 23, 2016 13:34
-
-
Save amarao/5d0d4346f9ce6183d05bdae197ba1fc4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# inside of 'module.py' | |
def init(): | |
if __name__ == "__main__": | |
sys.exit(main()) | |
init() | |
# inside of 'test_module.py' | |
def test_init(): | |
from myapp import module | |
with mock.patch.object(module, "main", return_value=42): | |
with mock.patch.object(module, "__name__", "__main__"): | |
with mock.patch.object(module.sys,'exit') as mock_exit: | |
module.init() | |
assert mock_exit.call_args[0][0] == 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment