Advertisement
Guest User

Untitled

a guest
May 24th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import mock
  3. import contextlib
  4.  
  5.  
  6. @contextlib.contextmanager
  7. def hoge():
  8. yield u'ハリルホジッチ'
  9.  
  10.  
  11. @contextlib.contextmanager
  12. def hoge_patched():
  13. yield u'パッチ着たハリルホジッチ'
  14.  
  15.  
  16. if __name__ == '__main__':
  17. with hoge() as x:
  18. print(x)
  19. # => ハリルホジッチ
  20.  
  21. with hoge_patched() as x:
  22. print(x)
  23. # => パッチ着たハリルホジッチ
  24.  
  25. with mock.patch('__main__.hoge',
  26. side_effect=hoge_patched):
  27. with hoge() as x:
  28. print(x)
  29. # => パッチ着たハリルホジッチ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement