Есть ли способ временно отменить исправление с помощью mock
в side_effect
?В частности, я хотел бы сделать что-то вроде этой работы:
from mock import patch
import urllib2
import unittest
class SimpleTest(unittest.TestCase):
def setUp(self):
self.urlpatcher = patch('urllib2.urlopen')
self.urlopen = self.urlpatcher.start()
def side_effect(url):
#do some interesting stuff first
#... temporary unpatch urllib2.urlopen so that we can call a real one here
r = urllib2.urlopen(url) #this ought to be the real deal now
#... patch it again
return r
self.urlopen.side_effect = side_effect
def test_feature(self):
#almost real urllib2.urlopen usage goes here
p = urllib2.urlopen("www.google.com").read()
if __name__ == '__main__':
unittest.main()