Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import mock
- import contextlib
- @contextlib.contextmanager
- def hoge():
- yield u'ハリルホジッチ'
- @contextlib.contextmanager
- def hoge_patched():
- yield u'パッチ着たハリルホジッチ'
- if __name__ == '__main__':
- with hoge() as x:
- print(x)
- # => ハリルホジッチ
- with hoge_patched() as x:
- print(x)
- # => パッチ着たハリルホジッチ
- with mock.patch('__main__.hoge',
- side_effect=hoge_patched):
- with hoge() as x:
- print(x)
- # => パッチ着たハリルホジッチ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement