summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-07-25 09:32:14 -0400
committerTim Graham <timograham@gmail.com>2014-07-25 13:25:16 -0400
commit4f8a5bd8d0f14280b25e4389b881f9f719159c38 (patch)
tree7825359e3e143adafdc13e124e3a840301aded6d
parent3268711417b3c67f6eb08bec3f39f2d51186e11b (diff)
[1.7.x] Fixed #23083 -- Fixed runserver reloading when deleting a file.
Thanks Collin Anderson for the report and hirokiky for the fix. Backport of b8cb5ba708 from master
-rw-r--r--django/utils/autoreload.py1
-rw-r--r--tests/utils_tests/test_autoreload.py13
2 files changed, 14 insertions, 0 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index b232a51fa0..cba555e301 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -88,6 +88,7 @@ def gen_filenames(only_new=False):
"""
global _cached_modules, _cached_filenames
module_values = set(sys.modules.values())
+ _cached_filenames = clean_files(_cached_filenames)
if _cached_modules == module_values:
# No changes in module list, short-circuit the function
if only_new:
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index e7ef8537c0..1edf3f9bf8 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -1,9 +1,12 @@
+from importlib import import_module
import os
+import tempfile
from django import conf
from django.contrib import admin
from django.test import TestCase, override_settings
from django.utils.autoreload import gen_filenames
+from django.utils._os import upath
LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale')
@@ -82,3 +85,13 @@ class TestFilenameGenerator(TestCase):
self.assertEqual(len(filenames2), 1)
self.assertTrue(filenames2[0].endswith('fractions.py'))
self.assertFalse(any(f.endswith('.pyc') for f in gen_filenames()))
+
+ def test_deleted_removed(self):
+ _, filepath = tempfile.mkstemp(dir=os.path.dirname(upath(__file__)), suffix='.py')
+ try:
+ _, filename = os.path.split(filepath)
+ import_module('.%s' % filename.rstrip('.py'), package='utils_tests')
+ self.assertIn(filepath, gen_filenames())
+ finally:
+ os.remove(filepath)
+ self.assertNotIn(filepath, gen_filenames())