本文整理汇总了Python中mock.patch.stopall函数的典型用法代码示例。如果您正苦于以下问题:Python stopall函数的具体用法?Python stopall怎么用?Python stopall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stopall函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mock_request
def mock_request(self, username, task):
"""
Patch get_object_or_404 to return given task.
Yield Mock request as context variable.
"""
patch("scores.views.get_object_or_404", Mock(side_effect=lambda *a, **k: task)).start()
yield Mock(user=self.users[username], method="GET", is_ajax=lambda: True, GET={"task_id": 1})
patch.stopall()
示例2: teardown_scenario
def teardown_scenario(scenario):
"""
Empty the temporary directory and restore the working directory.
"""
# remove the scenario variables
del world.scenario
# Remove the fixtures directory
shutil.rmtree(world.fixtures_dir)
# Restore the current working directory
os.chdir(world.old_cwd)
# Uninstall all mocks
patch.stopall()
示例3: _patched
def _patched(*args, **kwargs):
try:
for patch in patches:
mock = patch.start()
if isinstance(mock.kwargs_field, str):
kwargs[mock.kwargs_field] = mock
# Merge additional fields into kwargs with kwargs taking precedence
kwargs = dict(additional_fields.items() + kwargs.items())
retval = func(*args, **kwargs)
finally:
Patch.stopall()
return retval
示例4: test__method
def test__method(self):
""" Test Api._method rest submission """
ret = {'test': 'val'}
ret_val = RequestRet(content=json_dumps(ret).encode('utf-8'),
status_code=200)
post = patch('requests.post', return_value=ret_val).start()
delete = patch('requests.delete', return_value=ret_val).start()
get = patch('requests.get', return_value=ret_val).start()
# pylint:disable=protected-access
_auth = Mock()
# call get
ret = rest.Api._method(self._url)
get.assert_called_with(self._url, auth=None)
self.assertEquals(ret, ret)
ret = rest.Api._method(self._url, method='GET', auth=_auth)
get.assert_called_with(self._url, auth=_auth)
self.assertEquals(ret, ret)
# call delete
ret = rest.Api._method(self._url, method='DELETE')
delete.assert_called_with(self._url, auth=None)
self.assertEquals(ret, ret)
# call post
ret = rest.Api._method(self._url, method='POST', data={})
post.assert_called_with(
self._url, data='{}'.encode('utf-8'),
headers={'content-type': 'application/json'},
auth=None)
self.assertEquals(ret, ret)
# call multipart
_files = {'entry': '{}'}
ret = rest.Api._method(self._url, method='MULTIPART', data=_files)
post.assert_called_with(self._url, files=_files, auth=None)
self.assertEquals(ret, ret)
patch.stopall()
示例5: tearDown
def tearDown(self):
super(FakeFSTest, self).tearDown()
patch.stopall()
示例6: tearDown
def tearDown(self):
cache.clear()
patch.stopall()
示例7: tearDown
def tearDown(self):
super(TestBasicAuthPolicy, self).tearDown()
patch.stopall()
示例8: tearDown
def tearDown(self):
super(TestGoogleCloudStorage, self).tearDown()
patch.stopall()
示例9: tearDown
def tearDown(self):
super(TestAuth, self).tearDown()
patch.stopall()
示例10: teardown_module
def teardown_module(module):
"""Stop patches and enable logging output"""
patch.stopall()
logging.disable(logging.NOTSET)
示例11: teardown
def teardown(self):
super(BaseDealerTest, self).teardown()
patch.stopall()
# Reset dealer instance.
self.dealer = None
示例12: tearDown
def tearDown(self):
try:
os.remove(TEST_RC_FILE)
except OSError:
pass
patch.stopall()
示例13: tearDown
def tearDown(self):
patch.stopall()
if path.exists(TEST_WORKSPACE):
shutil.rmtree(TEST_WORKSPACE)
示例14: tearDown
def tearDown(self):
unittest.TestCase.tearDown(self)
patch.stopall()
示例15: tearDownModule
def tearDownModule():
patch.stopall()