From b5c7b6270233328a8539d965ec127e4dc219db6f Mon Sep 17 00:00:00 2001 From: anishTP Date: Fri, 10 Nov 2023 17:20:04 +0530 Subject: [PATCH] Add context manager for file handling --- tests/unit/views/preview_image_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/views/preview_image_test.py b/tests/unit/views/preview_image_test.py index 2c2dc438e..e4a6d5932 100644 --- a/tests/unit/views/preview_image_test.py +++ b/tests/unit/views/preview_image_test.py @@ -14,7 +14,7 @@ def test_preview_image_jobs(project_expo2011) -> None: @pytest.mark.usefixtures('project_expo2011', 'all_fixtures') def test_preview_image_size(project_expo2011) -> None: render_project_preview_image(project_id=project_expo2011.id) - preview_image = Image.open(io.BytesIO(project_expo2011.preview_image)) - result = from_buffer(io.BytesIO(project_expo2011.preview_image).read(2048), mime=True) - assert preview_image.size == (1280, 720) - assert result == 'image/png' + with Image.open(io.BytesIO(project_expo2011.preview_image)) as preview_image: + assert preview_image.size == (1280, 720) + image_mimetype = from_buffer(io.BytesIO(project_expo2011.preview_image).read(2048), mime=True) + assert image_mimetype == 'image/png'