Kaydet (Commit) 487d904b authored tarafından Jon Dufresne's avatar Jon Dufresne Kaydeden (comit) Tim Graham

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.
üst 099c36d5
This diff is collapsed.
...@@ -439,6 +439,7 @@ class SettingsConfigTest(AdminScriptTestCase): ...@@ -439,6 +439,7 @@ class SettingsConfigTest(AdminScriptTestCase):
a circular import error. a circular import error.
""" """
def setUp(self): def setUp(self):
super().setUp()
log_config = """{ log_config = """{
'version': 1, 'version': 1,
'handlers': { 'handlers': {
...@@ -450,9 +451,6 @@ class SettingsConfigTest(AdminScriptTestCase): ...@@ -450,9 +451,6 @@ class SettingsConfigTest(AdminScriptTestCase):
}""" }"""
self.write_settings('settings.py', sdict={'LOGGING': log_config}) self.write_settings('settings.py', sdict={'LOGGING': log_config})
def tearDown(self):
self.remove_settings('settings.py')
def test_circular_dependency(self): def test_circular_dependency(self):
# validate is just an example command to trigger settings configuration # validate is just an example command to trigger settings configuration
out, err = self.run_manage(['check']) out, err = self.run_manage(['check'])
...@@ -518,6 +516,7 @@ class SettingsCustomLoggingTest(AdminScriptTestCase): ...@@ -518,6 +516,7 @@ class SettingsCustomLoggingTest(AdminScriptTestCase):
callable in LOGGING_CONFIG (i.e., logging.config.fileConfig). callable in LOGGING_CONFIG (i.e., logging.config.fileConfig).
""" """
def setUp(self): def setUp(self):
super().setUp()
logging_conf = """ logging_conf = """
[loggers] [loggers]
keys=root keys=root
...@@ -544,7 +543,6 @@ format=%(message)s ...@@ -544,7 +543,6 @@ format=%(message)s
def tearDown(self): def tearDown(self):
self.temp_file.close() self.temp_file.close()
self.remove_settings('settings.py')
def test_custom_logging(self): def test_custom_logging(self):
out, err = self.run_manage(['check']) out, err = self.run_manage(['check'])
......
...@@ -155,14 +155,12 @@ class CustomTestRunnerOptionsSettingsTests(AdminScriptTestCase): ...@@ -155,14 +155,12 @@ class CustomTestRunnerOptionsSettingsTests(AdminScriptTestCase):
through a settings file. through a settings file.
""" """
def setUp(self): def setUp(self):
super().setUp()
settings = { settings = {
'TEST_RUNNER': '\'test_runner.runner.CustomOptionsTestRunner\'', 'TEST_RUNNER': '\'test_runner.runner.CustomOptionsTestRunner\'',
} }
self.write_settings('settings.py', sdict=settings) self.write_settings('settings.py', sdict=settings)
def tearDown(self):
self.remove_settings('settings.py')
def test_default_options(self): def test_default_options(self):
args = ['test', '--settings=test_project.settings'] args = ['test', '--settings=test_project.settings']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
...@@ -195,11 +193,9 @@ class CustomTestRunnerOptionsCmdlineTests(AdminScriptTestCase): ...@@ -195,11 +193,9 @@ class CustomTestRunnerOptionsCmdlineTests(AdminScriptTestCase):
using --testrunner. using --testrunner.
""" """
def setUp(self): def setUp(self):
super().setUp()
self.write_settings('settings.py') self.write_settings('settings.py')
def tearDown(self):
self.remove_settings('settings.py')
def test_testrunner_option(self): def test_testrunner_option(self):
args = [ args = [
'test', '--testrunner', 'test_runner.runner.CustomOptionsTestRunner', 'test', '--testrunner', 'test_runner.runner.CustomOptionsTestRunner',
...@@ -228,11 +224,9 @@ class CustomTestRunnerOptionsCmdlineTests(AdminScriptTestCase): ...@@ -228,11 +224,9 @@ class CustomTestRunnerOptionsCmdlineTests(AdminScriptTestCase):
class Ticket17477RegressionTests(AdminScriptTestCase): class Ticket17477RegressionTests(AdminScriptTestCase):
def setUp(self): def setUp(self):
super().setUp()
self.write_settings('settings.py') self.write_settings('settings.py')
def tearDown(self):
self.remove_settings('settings.py')
def test_ticket_17477(self): def test_ticket_17477(self):
"""'manage.py help test' works after r16352.""" """'manage.py help test' works after r16352."""
args = ['help', 'test'] args = ['help', 'test']
......
...@@ -534,14 +534,12 @@ class ReverseLazySettingsTest(AdminScriptTestCase): ...@@ -534,14 +534,12 @@ class ReverseLazySettingsTest(AdminScriptTestCase):
import error. import error.
""" """
def setUp(self): def setUp(self):
super().setUp()
self.write_settings( self.write_settings(
'settings.py', 'settings.py',
extra="from django.urls import reverse_lazy\nLOGIN_URL = reverse_lazy('login')", extra="from django.urls import reverse_lazy\nLOGIN_URL = reverse_lazy('login')",
) )
def tearDown(self):
self.remove_settings('settings.py')
def test_lazy_in_settings(self): def test_lazy_in_settings(self):
out, err = self.run_manage(['check']) out, err = self.run_manage(['check'])
self.assertNoOutput(err) self.assertNoOutput(err)
......
...@@ -234,9 +234,6 @@ class CommandRunTests(AdminScriptTestCase): ...@@ -234,9 +234,6 @@ class CommandRunTests(AdminScriptTestCase):
""" """
Tests that need to run by simulating the command line, not by call_command. Tests that need to run by simulating the command line, not by call_command.
""" """
def tearDown(self):
self.remove_settings('settings.py')
def test_script_prefix_set_in_commands(self): def test_script_prefix_set_in_commands(self):
self.write_settings('settings.py', apps=['user_commands'], sdict={ self.write_settings('settings.py', apps=['user_commands'], sdict={
'ROOT_URLCONF': '"user_commands.urls"', 'ROOT_URLCONF': '"user_commands.urls"',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment