def run(self, *args, **kwargs): # Have to do this mock_import gymnastics because the imports inside the # autodiscovery module are local imports with mock_import('django.conf.settings') as mock_settings: mock_settings.INSTALLED_APPS = ['foo.bar'] with mock_import('django.utils.importlib.import_module') as im: self.import_module = im super(AutodiscoverTest, self).run(*args, **kwargs)
def test_mocks_import_for_packages(self): with mock_import('foo.bar.baz') as mock_baz: import foo.bar.baz self.assertEqual(foo.bar.baz, mock_baz)
def test_is_a_context_manager_that_yields_patched_import(self): with mock_import('foo') as mock_foo: import foo self.assertEqual(foo, mock_foo)
def test_mocks_import_for_packages(self): with mock_import('foo.bar.baz') as mock_baz: import foo.bar.baz expect(foo.bar.baz).to == mock_baz
def test_is_a_context_manager_that_yields_patched_import(self): with mock_import('foo') as mock_foo: import foo expect(foo).to == mock_foo