1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Simplified temporary directory handling in AdminScriptTestCase.

Use tempfile.TemporaryDirectory() in AdminScriptTestCase.setUp()
to create and destroy a temporary directory for each test. It removes
the need for individual tests to delete files.

For test classes that don't use the temporary directory, inherit from
SimpleTestCase.
This commit is contained in:
Jon Dufresne
2019-02-05 09:11:54 -08:00
committed by Tim Graham
parent 099c36d546
commit 487d904bf2
5 changed files with 30 additions and 140 deletions

View File

@@ -439,6 +439,7 @@ class SettingsConfigTest(AdminScriptTestCase):
a circular import error.
"""
def setUp(self):
super().setUp()
log_config = """{
'version': 1,
'handlers': {
@@ -450,9 +451,6 @@ class SettingsConfigTest(AdminScriptTestCase):
}"""
self.write_settings('settings.py', sdict={'LOGGING': log_config})
def tearDown(self):
self.remove_settings('settings.py')
def test_circular_dependency(self):
# validate is just an example command to trigger settings configuration
out, err = self.run_manage(['check'])
@@ -518,6 +516,7 @@ class SettingsCustomLoggingTest(AdminScriptTestCase):
callable in LOGGING_CONFIG (i.e., logging.config.fileConfig).
"""
def setUp(self):
super().setUp()
logging_conf = """
[loggers]
keys=root
@@ -544,7 +543,6 @@ format=%(message)s
def tearDown(self):
self.temp_file.close()
self.remove_settings('settings.py')
def test_custom_logging(self):
out, err = self.run_manage(['check'])