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):
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'])
......
......@@ -155,14 +155,12 @@ class CustomTestRunnerOptionsSettingsTests(AdminScriptTestCase):
through a settings file.
"""
def setUp(self):
super().setUp()
settings = {
'TEST_RUNNER': '\'test_runner.runner.CustomOptionsTestRunner\'',
}
self.write_settings('settings.py', sdict=settings)
def tearDown(self):
self.remove_settings('settings.py')
def test_default_options(self):
args = ['test', '--settings=test_project.settings']
out, err = self.run_django_admin(args)
......@@ -195,11 +193,9 @@ class CustomTestRunnerOptionsCmdlineTests(AdminScriptTestCase):
using --testrunner.
"""
def setUp(self):
super().setUp()
self.write_settings('settings.py')
def tearDown(self):
self.remove_settings('settings.py')
def test_testrunner_option(self):
args = [
'test', '--testrunner', 'test_runner.runner.CustomOptionsTestRunner',
......@@ -228,11 +224,9 @@ class CustomTestRunnerOptionsCmdlineTests(AdminScriptTestCase):
class Ticket17477RegressionTests(AdminScriptTestCase):
def setUp(self):
super().setUp()
self.write_settings('settings.py')
def tearDown(self):
self.remove_settings('settings.py')
def test_ticket_17477(self):
"""'manage.py help test' works after r16352."""
args = ['help', 'test']
......
......@@ -534,14 +534,12 @@ class ReverseLazySettingsTest(AdminScriptTestCase):
import error.
"""
def setUp(self):
super().setUp()
self.write_settings(
'settings.py',
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):
out, err = self.run_manage(['check'])
self.assertNoOutput(err)
......
......@@ -234,9 +234,6 @@ class CommandRunTests(AdminScriptTestCase):
"""
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):
self.write_settings('settings.py', apps=['user_commands'], sdict={
'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