From f452d1f0ffa6fb408657ea81c6e3bbe9ae821677 Mon Sep 17 00:00:00 2001 From: jahwag Date: Sat, 30 Nov 2024 16:29:21 +0100 Subject: [PATCH] fix: start mock http server once --- tests/mock_http_server_fixture.py | 22 ++++++++++++++++++++++ tests/test_chat_happy_path.py | 8 -------- tests/test_claude_ai.py | 7 ------- tests/test_happy_path.py | 8 -------- 4 files changed, 22 insertions(+), 23 deletions(-) create mode 100644 tests/mock_http_server_fixture.py diff --git a/tests/mock_http_server_fixture.py b/tests/mock_http_server_fixture.py new file mode 100644 index 0000000..2a39484 --- /dev/null +++ b/tests/mock_http_server_fixture.py @@ -0,0 +1,22 @@ +import pytest +import threading +import time +from mock_http_server import run_mock_server + +@pytest.fixture(scope="session") +def mock_server(): + """Start the mock server once for the entire test suite.""" + # Start server in a daemon thread + server_thread = threading.Thread(target=run_mock_server) + server_thread.daemon = True + server_thread.start() + + # Give the server time to start + time.sleep(1) + + yield server_thread + +@pytest.fixture(autouse=True) +def use_mock_server(mock_server): + """Automatically use the mock server for all tests.""" + pass \ No newline at end of file diff --git a/tests/test_chat_happy_path.py b/tests/test_chat_happy_path.py index f535f97..303b821 100644 --- a/tests/test_chat_happy_path.py +++ b/tests/test_chat_happy_path.py @@ -8,14 +8,6 @@ class TestChatHappyPath(unittest.TestCase): - @classmethod - def setUpClass(cls): - # Start the mock server in a separate thread - cls.mock_server_thread = threading.Thread(target=run_mock_server) - cls.mock_server_thread.daemon = True - cls.mock_server_thread.start() - time.sleep(1) # Give the server a moment to start - def setUp(self): self.runner = CliRunner() self.config = InMemoryConfigManager() diff --git a/tests/test_claude_ai.py b/tests/test_claude_ai.py index 14dd2c8..e8282d2 100644 --- a/tests/test_claude_ai.py +++ b/tests/test_claude_ai.py @@ -11,13 +11,6 @@ class TestClaudeAIProvider(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.mock_server_thread = threading.Thread(target=run_mock_server) - cls.mock_server_thread.daemon = True - cls.mock_server_thread.start() - time.sleep(1) - def setUp(self): self.config = InMemoryConfigManager() self.config.set("claude_api_url", "http://127.0.0.1:8000/api") diff --git a/tests/test_happy_path.py b/tests/test_happy_path.py index 4137a6a..0404594 100644 --- a/tests/test_happy_path.py +++ b/tests/test_happy_path.py @@ -9,14 +9,6 @@ class TestClaudeSyncHappyPath(unittest.TestCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.mock_server_thread = threading.Thread(target=run_mock_server) - cls.mock_server_thread.daemon = True - cls.mock_server_thread.start() - time.sleep(1) # Wait for the mock server to start - def setUp(self): self.runner = CliRunner() self.config = InMemoryConfigManager()