diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-06-04 12:53:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-04 12:53:11 +0200 |
| commit | 213850b4b9641bdcb714172999725ec9aa9c9e84 (patch) | |
| tree | a62f1a50c2b78b2c944b7c7d9167efadf5910d4f | |
| parent | 2e4711c611896ae6490d3fa3f8d0c506f2ff3673 (diff) | |
Refs #32355 -- Used addClassCleanup() in tests.
Inspired by Adam Johnson talk on DjangoCon Europe 2021.
| -rw-r--r-- | tests/file_uploads/tests.py | 12 | ||||
| -rw-r--r-- | tests/logging_tests/tests.py | 7 | ||||
| -rw-r--r-- | tests/mail/tests.py | 8 |
3 files changed, 5 insertions, 22 deletions
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py index 7bc8d41dac..8b5d1de26f 100644 --- a/tests/file_uploads/tests.py +++ b/tests/file_uploads/tests.py @@ -58,11 +58,7 @@ class FileUploadTests(TestCase): def setUpClass(cls): super().setUpClass() os.makedirs(MEDIA_ROOT, exist_ok=True) - - @classmethod - def tearDownClass(cls): - shutil.rmtree(MEDIA_ROOT) - super().tearDownClass() + cls.addClassCleanup(shutil.rmtree, MEDIA_ROOT) def test_upload_name_is_validated(self): candidates = [ @@ -678,11 +674,7 @@ class DirectoryCreationTests(SimpleTestCase): def setUpClass(cls): super().setUpClass() os.makedirs(MEDIA_ROOT, exist_ok=True) - - @classmethod - def tearDownClass(cls): - shutil.rmtree(MEDIA_ROOT) - super().tearDownClass() + cls.addClassCleanup(shutil.rmtree, MEDIA_ROOT) def setUp(self): self.obj = FileModel() diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index e565905795..a06cda9efa 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -53,13 +53,8 @@ class SetupDefaultLoggingMixin: @classmethod def setUpClass(cls): super().setUpClass() - cls._logging = settings.LOGGING logging.config.dictConfig(DEFAULT_LOGGING) - - @classmethod - def tearDownClass(cls): - super().tearDownClass() - logging.config.dictConfig(cls._logging) + cls.addClassCleanup(logging.config.dictConfig, settings.LOGGING) class DefaultLoggingTests(SetupDefaultLoggingMixin, LoggingCaptureMixin, SimpleTestCase): diff --git a/tests/mail/tests.py b/tests/mail/tests.py index de8ff159c0..30f8252e0a 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -1442,13 +1442,9 @@ class SMTPBackendTestsBase(SimpleTestCase): EMAIL_HOST="127.0.0.1", EMAIL_PORT=cls.server.socket.getsockname()[1]) cls._settings_override.enable() + cls.addClassCleanup(cls._settings_override.disable) cls.server.start() - - @classmethod - def tearDownClass(cls): - cls._settings_override.disable() - cls.server.stop() - super().tearDownClass() + cls.addClassCleanup(cls.server.stop) class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase): |
