Skip to content

Instantly share code, notes, and snippets.

Created Oct 5, 2015
What would you like to do?
my_singleton = None
class Foo(object):
def __init__(self):
def do(arg):
return arg
def process_foo(foo, arg):
def do_something():
# Heavy API call
raise Exception()
return 1
def logic():
# something
api_response = do_something()
# something
return api_response
def print_singleton():
return my_singleton
######### testfile
from unittest import mock
import demo
from demo import my_singleton
foo_mock = mock.Mock()
demo.process_foo(foo_mock, 4)
def test_logic(m):
m.return_value = 1
result = demo.logic()
assert result == 1
demo.my_singleton = 5
my_singleton = 6
assert demo.print_singleton() == 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment