From 98da408964b229ee0b35bb8c4500820e3606aeab Mon Sep 17 00:00:00 2001 From: Markus Holtermann Date: Fri, 31 Oct 2014 10:22:15 +0100 Subject: Fixed #23670 -- Prevented partial import state during module autodiscovery Thanks kostko for the report. --- tests/utils_tests/test_module_loading.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/utils_tests/test_module_loading.py') diff --git a/tests/utils_tests/test_module_loading.py b/tests/utils_tests/test_module_loading.py index 9cdaf8df09..31608bfcc1 100644 --- a/tests/utils_tests/test_module_loading.py +++ b/tests/utils_tests/test_module_loading.py @@ -155,6 +155,15 @@ class ModuleImportTestCase(IgnoreDeprecationWarningsMixin, unittest.TestCase): @modify_settings(INSTALLED_APPS={'append': 'utils_tests.test_module'}) class AutodiscoverModulesTestCase(SimpleTestCase): + def tearDown(self): + sys.path_importer_cache.clear() + + sys.modules.pop('utils_tests.test_module.another_bad_module', None) + sys.modules.pop('utils_tests.test_module.another_good_module', None) + sys.modules.pop('utils_tests.test_module.bad_module', None) + sys.modules.pop('utils_tests.test_module.good_module', None) + sys.modules.pop('utils_tests.test_module', None) + def test_autodiscover_modules_found(self): autodiscover_modules('good_module') @@ -172,12 +181,28 @@ class AutodiscoverModulesTestCase(SimpleTestCase): def test_autodiscover_modules_several_found(self): autodiscover_modules('good_module', 'another_good_module') + def test_autodiscover_modules_several_found_with_registry(self): + from .test_module import site + autodiscover_modules('good_module', 'another_good_module', register_to=site) + self.assertEqual(site._registry, {'lorem': 'ipsum'}) + def test_validate_registry_keeps_intact(self): from .test_module import site with six.assertRaisesRegex(self, Exception, "Some random exception."): autodiscover_modules('another_bad_module', register_to=site) self.assertEqual(site._registry, {}) + def test_validate_registry_resets_after_erroneous_module(self): + from .test_module import site + with six.assertRaisesRegex(self, Exception, "Some random exception."): + autodiscover_modules('another_good_module', 'another_bad_module', register_to=site) + self.assertEqual(site._registry, {'lorem': 'ipsum'}) + + def test_validate_registry_resets_after_missing_module(self): + from .test_module import site + autodiscover_modules('does_not_exist', 'another_good_module', 'does_not_exist2', register_to=site) + self.assertEqual(site._registry, {'lorem': 'ipsum'}) + class ProxyFinder(object): def __init__(self): -- cgit v1.3