Refs #32355 -- Used addClassCleanup() in tests.

Inspired by Adam Johnson talk on DjangoCon Europe 2021.
This commit is contained in:
Mariusz Felisiak 2021-06-04 12:53:11 +02:00 committed by GitHub
parent 2e4711c611
commit 213850b4b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 22 deletions

View File

@ -58,11 +58,7 @@ class FileUploadTests(TestCase):
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
os.makedirs(MEDIA_ROOT, exist_ok=True) os.makedirs(MEDIA_ROOT, exist_ok=True)
cls.addClassCleanup(shutil.rmtree, MEDIA_ROOT)
@classmethod
def tearDownClass(cls):
shutil.rmtree(MEDIA_ROOT)
super().tearDownClass()
def test_upload_name_is_validated(self): def test_upload_name_is_validated(self):
candidates = [ candidates = [
@ -678,11 +674,7 @@ class DirectoryCreationTests(SimpleTestCase):
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
os.makedirs(MEDIA_ROOT, exist_ok=True) os.makedirs(MEDIA_ROOT, exist_ok=True)
cls.addClassCleanup(shutil.rmtree, MEDIA_ROOT)
@classmethod
def tearDownClass(cls):
shutil.rmtree(MEDIA_ROOT)
super().tearDownClass()
def setUp(self): def setUp(self):
self.obj = FileModel() self.obj = FileModel()

View File

@ -53,13 +53,8 @@ class SetupDefaultLoggingMixin:
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
cls._logging = settings.LOGGING
logging.config.dictConfig(DEFAULT_LOGGING) logging.config.dictConfig(DEFAULT_LOGGING)
cls.addClassCleanup(logging.config.dictConfig, settings.LOGGING)
@classmethod
def tearDownClass(cls):
super().tearDownClass()
logging.config.dictConfig(cls._logging)
class DefaultLoggingTests(SetupDefaultLoggingMixin, LoggingCaptureMixin, SimpleTestCase): class DefaultLoggingTests(SetupDefaultLoggingMixin, LoggingCaptureMixin, SimpleTestCase):

View File

@ -1442,13 +1442,9 @@ class SMTPBackendTestsBase(SimpleTestCase):
EMAIL_HOST="127.0.0.1", EMAIL_HOST="127.0.0.1",
EMAIL_PORT=cls.server.socket.getsockname()[1]) EMAIL_PORT=cls.server.socket.getsockname()[1])
cls._settings_override.enable() cls._settings_override.enable()
cls.addClassCleanup(cls._settings_override.disable)
cls.server.start() cls.server.start()
cls.addClassCleanup(cls.server.stop)
@classmethod
def tearDownClass(cls):
cls._settings_override.disable()
cls.server.stop()
super().tearDownClass()
class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase): class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase):