Skip to content

Commit

Permalink
fix: start mock http server once
Browse files Browse the repository at this point in the history
  • Loading branch information
jahwag committed Nov 30, 2024
1 parent 6008baf commit f452d1f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
22 changes: 22 additions & 0 deletions tests/mock_http_server_fixture.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions tests/test_chat_happy_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 0 additions & 7 deletions tests/test_claude_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 0 additions & 8 deletions tests/test_happy_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f452d1f

Please sign in to comment.