Skip to content

Instantly share code, notes, and snippets.

@amarao
Created December 23, 2016 13:34
Show Gist options
  • Save amarao/5d0d4346f9ce6183d05bdae197ba1fc4 to your computer and use it in GitHub Desktop.
Save amarao/5d0d4346f9ce6183d05bdae197ba1fc4 to your computer and use it in GitHub Desktop.
# 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