From 27e156fa316e9e51e4bce1277bd0fa02b07cd16a Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 24 Jun 2021 11:47:29 +0200 Subject: [PATCH] Fixed ResourceWarning in test_client.tests.ClientTest.test_uploading_named_temp_file(). --- tests/test_client/tests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py index a808cc9763..d9be3416f2 100644 --- a/tests/test_client/tests.py +++ b/tests/test_client/tests.py @@ -894,8 +894,11 @@ class ClientTest(TestCase): self.assertEqual(response.content, b'temp_file') def test_uploading_named_temp_file(self): - test_file = tempfile.NamedTemporaryFile() - response = self.client.post('/upload_view/', data={'named_temp_file': test_file}) + with tempfile.NamedTemporaryFile() as test_file: + response = self.client.post( + '/upload_view/', + data={'named_temp_file': test_file}, + ) self.assertEqual(response.content, b'named_temp_file')