我们从Python开源项目中,提取了以下43个代码示例,用于说明如何使用mock.patch.stopall()。
def setUp(self): # Cleanup self.addCleanup(patch.stopall) # Request patch self.request = patch.object(module, 'request').start() # Various patches self.services = patch.object(module, 'services').start() self.original_config = dict(module.config) module.config['STORAGE_BUCKET_NAME'] = self.bucket = 'buckbuck' module.config['STORAGE_ACCESS_KEY_ID'] = '' module.config['STORAGE_SECRET_ACCESS_KEY'] = '' module.config['ACCESS_KEY_EXPIRES_IN'] = '' module.config['STORAGE_PATH_PATTERN'] = '{owner}/{dataset}/{path}' self.s3 = boto3.client('s3')
def setUp(self): super(CopytoolTestCase, self).setUp() from chroma_agent.config_store import ConfigStore self.mock_config = ConfigStore(tempfile.mkdtemp()) patch('chroma_agent.copytool_monitor.config', self.mock_config).start() self.ct_id = '42' self.ct_bin_path = '/usr/sbin/lhsmtool_foo' self.ct_filesystem = 'testfs' self.ct_mountpoint = '/mnt/testfs' self.ct_archive = 2 self.ct_index = 0 self.ct = Copytool(self.ct_id, self.ct_index, self.ct_bin_path, self.ct_archive, self.ct_filesystem, self.ct_mountpoint, "") self.addCleanup(patch.stopall)
def setUp(self): super(PactSetupTestCase, self).setUp() self.addCleanup(patch.stopall) self.mock_requests = patch('requests.api.request').start() self.target = Pact(self.consumer, self.provider) (self.target .given('I am creating a new pact using the Pact class') .upon_receiving('a specific request to the server') .with_request('GET', '/path') .will_respond_with(200, body='success')) self.delete_call = call('delete', 'http://localhost:1234/interactions', headers={'X-Pact-Mock-Service': 'true'}) self.put_interactions_call = call( 'put', 'http://localhost:1234/interactions', data=None, headers={'X-Pact-Mock-Service': 'true'}, json={'interactions': [{ 'response': {'status': 200, 'body': 'success'}, 'request': {'path': '/path', 'method': 'GET'}, 'description': 'a specific request to the server', 'provider_state': 'I am creating a new pact using the ' 'Pact class'}]})
def setUp(self): super(PactVerifyTestCase, self).setUp() self.addCleanup(patch.stopall) self.mock_requests = patch('requests.api.request').start() self.target = Pact(self.consumer, self.provider) (self.target .given('I am creating a new pact using the Pact class') .upon_receiving('a specific request to the server') .with_request('GET', '/path') .will_respond_with(200, body='success')) self.get_verification_call = call( 'get', 'http://localhost:1234/interactions/verification', allow_redirects=True, headers={'X-Pact-Mock-Service': 'true'}, params=None) self.post_publish_pacts_call = call( 'post', 'http://localhost:1234/pact', data=None, headers={'X-Pact-Mock-Service': 'true'}, json={'pact_dir': os.getcwd(), 'consumer': {'name': 'TestConsumer'}, 'provider': {'name': 'TestProvider'}})
def tearDown(self): unittest.TestCase.tearDown(self) patch.stopall()
def tearDown(self): patch.stopall()
def tearDown(self): self.testbed.deactivate() patch.stopall()
def setUp(self): self.addCleanup(patch.stopall) # Tests
def setUp(self): self.echo_patch = patch.object(pyqubes.enact, 'echo').start() self.call_patch = patch.object(pyqubes.enact, 'call').start() self.addCleanup(patch.stopall)
def setUp(self): self.enact_patch = patch.object(pyqubes.vm.VM, 'enact').start() self.addCleanup(patch.stopall) self.vm = pyqubes.vm.VM("bounding")
def setUp(self): self.enter_patch = patch.object(pyqubes.vm.VM, 'firewall_open').start() self.exit_patch = patch.object(pyqubes.vm.VM, 'firewall_close').start() self.addCleanup(patch.stopall) self.vm = pyqubes.vm.TemplateVM("magic")
def setUp(self): self.enter_patch = patch.object(pyqubes.vm.VM, 'start').start() self.exit_patch = patch.object(pyqubes.vm.VM, 'shutdown').start() self.addCleanup(patch.stopall) self.vm = pyqubes.vm.TemplateVM("magic")
def setUp(self): self.enact_patch = patch.object(pyqubes.vm.VM, 'enact').start() self.addCleanup(patch.stopall)
def setUp(self): self.print_patch = patch.object(six, 'print_').start() self.addCleanup(patch.stopall)
def _post_teardown(self): """ Disable all mocks after the test. """ if self.mock_requests: responses.reset() responses.stop() patch.stopall()
def tearDown(self): super(TestScope, self).tearDown() patch.stopall()
def setUp(self): self.addCleanup(patch.stopall) self.controllers = patch.object(module, 'controllers').start() # Tests
def setUp(self): fill_db() request = request_factory.post('') request.session = SessionStore() set_up_session(request.session) cart = Cart(request) mock_update = Mock(wraps=cart.update) patch.object(cart, 'update', mock_update).start() self.addCleanup(patch.stopall) self.mock_update = mock_update self.request = request self.cart = cart self.cart_session = request.session[SESSION_KEY]
def setUp(self): super(CopytoolMonitorTestCase, self).setUp() self.client = Mock() self.copytool = Mock() self.copytool.event_fifo = '/var/spool/test-fifo' self.monitor = CopytoolMonitor(self.client, self.copytool) self.addCleanup(patch.stopall)
def teardown_module(module): """Stop patches and enable logging output""" patch.stopall() logging.disable(logging.NOTSET)
def setUp(self): super(PactStartShutdownServerTestCase, self).setUp() self.addCleanup(patch.stopall) self.mock_Popen = patch.object(pact, 'Popen', autospec=True).start() self.mock_Popen.return_value.returncode = 0 self.mock_Process = patch.object( pact.psutil, 'Process', autospec=True).start() self.mock_platform = patch.object( pact.platform, 'platform', autospec=True).start() self.mock_wait_for_server_start = patch.object( pact.Pact, '_wait_for_server_start', autospec=True).start()
def setUp(self): super(PactWaitForServerStartTestCase, self).setUp() self.addCleanup(patch.stopall) self.mock_HTTPAdapter = patch.object( pact, 'HTTPAdapter', autospec=True).start() self.mock_Retry = patch.object(pact, 'Retry', autospec=True).start() self.mock_Session = patch.object( pact.requests, 'Session', autospec=True).start()
def setUp(self): super(PactContextManagerTestCase, self).setUp() self.addCleanup(patch.stopall) self.mock_setup = patch.object( pact.Pact, 'setup', autospec=True).start() self.mock_verify = patch.object( pact.Pact, 'verify', autospec=True).start()
def setUp(self): super(expand_directoriesTestCase, self).setUp() def posix_join(*args): return '/'.join(args) self.addCleanup(patch.stopall) self.mock_isdir = patch.object(verify, 'isdir', autospec=True).start() self.mock_join = patch.object( verify, 'join', new=posix_join).start() self.mock_listdir = patch.object( verify, 'listdir', autospec=True).start()
def setUp(self): super(path_existsTestCase, self).setUp() self.addCleanup(patch.stopall) self.mock_isfile = patch.object( verify, 'isfile', autospec=True).start()
def setUp(self): self.addCleanup(patch.stopall) self.mock_platform = patch.object( verify.platform, 'platform', autospec=True).start()
def setUp(self): super(mock_service_exeTestCase, self).setUp() self.addCleanup(patch.stopall) self.mock_os = patch.object(constants, 'os', autospec=True).start()
def setUp(self): super(provider_verifier_exeTestCase, self).setUp() self.addCleanup(patch.stopall) self.mock_os = patch.object(constants, 'os', autospec=True).start()
def teardown_module(): patch.stopall()