Skip to content

Instantly share code, notes, and snippets.

@untitaker
Last active December 19, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save untitaker/6038880 to your computer and use it in GitHub Desktop.
Save untitaker/6038880 to your computer and use it in GitHub Desktop.
Mocking modules
import sublime
def better_os():
x = sublime.get_os()
if x:
return x.upper()
else:
return None
import sys
from mock import patch
class FakeSublime():
pass
sys.modules['sublime'] = FakeSublime
import sublime
import my_module
def test_stuff():
with patch('sublime.get_os', new=lambda: 'windows', create=True):
assert my_module.better_os() == 'WINDOWS'
with patch('sublime.get_os', new=lambda: False, create=True):
assert my_module.better_os() is None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment