From d88ec42bd0a37340c8477a6f20bf26e58bd84735 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Sun, 31 Dec 2023 10:01:31 +0100 Subject: Used addCleanup() in tests where appropriate. --- tests/model_fields/test_imagefield.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'tests/model_fields') diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py index 8bbfee30f2..8c93ed1bdb 100644 --- a/tests/model_fields/test_imagefield.py +++ b/tests/model_fields/test_imagefield.py @@ -55,20 +55,13 @@ class ImageFieldTestMixin(SerializeMixin): if os.path.exists(temp_storage_dir): shutil.rmtree(temp_storage_dir) os.mkdir(temp_storage_dir) - + self.addCleanup(shutil.rmtree, temp_storage_dir) file_path1 = os.path.join(os.path.dirname(__file__), "4x8.png") self.file1 = self.File(open(file_path1, "rb"), name="4x8.png") - + self.addCleanup(self.file1.close) file_path2 = os.path.join(os.path.dirname(__file__), "8x4.png") self.file2 = self.File(open(file_path2, "rb"), name="8x4.png") - - def tearDown(self): - """ - Removes temp directory and all its contents. - """ - self.file1.close() - self.file2.close() - shutil.rmtree(temp_storage_dir) + self.addCleanup(self.file2.close) def check_dimensions(self, instance, width, height, field_name="mugshot"): """ -- cgit v1.3