Skip to content

Commit 64c8af3

Browse files
fix: Resolve test isolation bug in pairing integration tests
Use temporary directories for each test to prevent state leakage between test runs. Previously, all tests shared the default global pairing store path, causing paired users to persist across tests. - Add tempfile.mkdtemp() for isolated test directories - Add teardown_method() to clean up temporary directories - Each test now gets fresh pairing store, fixing false failures Fixes test isolation issue where test_owner_approval_allows_future_messages was affecting subsequent tests by persisting pairing state.
1 parent 735ccad commit 64c8af3

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/praisonai/tests/integration/bots/test_pairing_owner_dm.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"""
66

77
import pytest
8+
import tempfile
9+
import shutil
810
from unittest.mock import AsyncMock, MagicMock
911
from typing import Dict, List
1012

@@ -56,7 +58,8 @@ class TestPairingOwnerDM:
5658
def setup_method(self):
5759
"""Set up test environment."""
5860
self.adapter = StubBotAdapter()
59-
self.pairing_store = PairingStore()
61+
self._pairing_dir = tempfile.mkdtemp(prefix="test_pairing_")
62+
self.pairing_store = PairingStore(store_dir=self._pairing_dir)
6063
self.config = BotConfig(
6164
unknown_user_policy="pair",
6265
owner_user_id="owner-123"
@@ -66,6 +69,10 @@ def setup_method(self):
6669
pairing_store=self.pairing_store,
6770
adapter=self.adapter
6871
)
72+
73+
def teardown_method(self):
74+
"""Clean up test environment."""
75+
shutil.rmtree(self._pairing_dir, ignore_errors=True)
6976

7077
def create_test_message(self, user_id: str = "new-user", user_name: str = "Alice") -> BotMessage:
7178
"""Create a test message from an unknown user."""

0 commit comments

Comments
 (0)