From 7b04f664cd9a9fbee21e7d4e722b5c8eb4b38708 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Mon, 23 Sep 2024 17:19:13 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85(backend)=20fix=20flaky=20test=20on=20?= =?UTF-8?q?tmp=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems to have a race condition, sometimes the tmp file is not deleted before the test assertion. We let the test sleep for 0.5 second before the assertion. --- src/backend/core/tests/test_models_templates.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/core/tests/test_models_templates.py b/src/backend/core/tests/test_models_templates.py index f6a48fd4..d38fcea9 100644 --- a/src/backend/core/tests/test_models_templates.py +++ b/src/backend/core/tests/test_models_templates.py @@ -3,6 +3,7 @@ Unit tests for the Template model """ import os +import time from unittest import mock from django.contrib.auth.models import AnonymousUser @@ -203,7 +204,7 @@ def test_models_templates__generate_word(): "pypandoc.convert_text", side_effect=RuntimeError("Conversion failed"), ) -def test_models_templates__generate_word__raise_error(_mock_send_mail): +def test_models_templates__generate_word__raise_error(_mock_pypandoc): """ Generate word document and assert no tmp files are left in /tmp folder even when the conversion fails. @@ -214,4 +215,5 @@ def test_models_templates__generate_word__raise_error(_mock_send_mail): template.generate_word("

Test body

", {}) except RuntimeError as e: assert str(e) == "Conversion failed" + time.sleep(0.5) assert len([f for f in os.listdir("/tmp") if f.startswith("docx_")]) == 0