diff options
Diffstat (limited to 'tests/utils_tests/test_module_loading.py')
| -rw-r--r-- | tests/utils_tests/test_module_loading.py | 25 |
1 files changed, 25 insertions, 0 deletions
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): |
