Как найти способ автоматического удаления tem dir и файлов после дебаггинга тестов в Django?

Проект Django. В этом проекте unittests. После процесса дебаггинга сделал temp dir и файлы, и не удаляю автоматически. sys MacOs. После теста temp dir и файлы удаляются, но после отладки этого теста они все еще там.

тестовый пример:



@override_settings(MEDIA_ROOT=TEMP_MEDIA_ROOT)
class PostCreateFormTests(TestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.small_gif = (
            b'\x47\x49\x46\x38\x39\x61\x02\x00'
            b'\x01\x00\x80\x00\x00\x00\x00\x00'
            b'\xFF\xFF\xFF\x21\xF9\x04\x00\x00'
            b'\x00\x00\x00\x2C\x00\x00\x00\x00'
            b'\x02\x00\x01\x00\x00\x02\x02\x0C'
            b'\x0A\x00\x3B'
        )
        cls.uploaded_image = SimpleUploadedFile(
            name='small.gif',
            content=cls.small_gif,
            content_type='image/gif'
        )



@classmethod def tearDownClass(cls): super().tearDownClass() shutil.rmtree(TEMP_MEDIA_ROOT, ignore_errors=True)



def test_create_post_form_valid_by_authorized_user(self):

posts_count = Post.objects.count()
form_data = {
    'text': 'Тестовая запись',
    'group': self.group.id,
    'image': self.uploaded_image
}
response = self.authorized_client.post(
    reverse('posts:post_create'),
    data=form_data,
    follow=True
)
self.assertEqual(Post.objects.count(), posts_count + 1)
self.assertTrue(
    Post.objects.filter(
        text=form_data['text'],
        group=form_data['group'],
        image='posts/small.gif'
    ).exists()
)
redirect = reverse(
    'posts:profile', kwargs={'username': self.user.username})
self.func_redirect_and_tests_post_correct_created_form_fields(
    response, form_data, redirect)


Найдите способ сделать удаление временных файлов процесса автоматическим .

Вернуться на верх