Skip to content

Commit

Permalink
✅(backend) fix flaky test on tmp file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AntoLC committed Sep 24, 2024
1 parent 358508f commit 7b04f66
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/backend/core/tests/test_models_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import time
from unittest import mock

from django.contrib.auth.models import AnonymousUser
Expand Down Expand Up @@ -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.
Expand All @@ -214,4 +215,5 @@ def test_models_templates__generate_word__raise_error(_mock_send_mail):
template.generate_word("<p>Test body</p>", {})
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

0 comments on commit 7b04f66

Please sign in to comment.