fix: unit test refactoring with conftest and more mocks
ref: N25B-205
This commit is contained in:
57
test/integration/conftest.py
Normal file
57
test/integration/conftest.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import sys
|
||||
from unittest.mock import MagicMock, AsyncMock
|
||||
|
||||
class DummyCyclicBehaviour:
|
||||
async def run(self):
|
||||
pass
|
||||
|
||||
def kill(self):
|
||||
self.is_killed = True
|
||||
return None
|
||||
|
||||
class DummyAgent:
|
||||
def __init__(self, jid=None, password=None, *_, **__):
|
||||
self.jid = jid
|
||||
self.password = password
|
||||
self.behaviours = []
|
||||
|
||||
async def start(self):
|
||||
return AsyncMock()
|
||||
|
||||
def add_behaviour(self, behaviour):
|
||||
behaviour.agent = self
|
||||
self.behaviours.append(behaviour)
|
||||
|
||||
async def stop(self):
|
||||
pass
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
"""
|
||||
This hook runs at the start of the pytest session, before any tests are
|
||||
collected. It mocks heavy or unavailable modules to prevent ImportErrors.
|
||||
"""
|
||||
# --- Mock spade and spade-bdi ---
|
||||
mock_spade = MagicMock()
|
||||
mock_spade.agent = MagicMock(Agent=DummyAgent)
|
||||
mock_spade.behaviour = MagicMock(CyclicBehaviour=DummyCyclicBehaviour)
|
||||
mock_spade_bdi = MagicMock()
|
||||
mock_spade_bdi.bdi = MagicMock()
|
||||
|
||||
mock_spade.agent.Message = MagicMock()
|
||||
|
||||
sys.modules["spade"] = mock_spade
|
||||
sys.modules["spade.agent"] = mock_spade.agent
|
||||
sys.modules["spade.behaviour"] = mock_spade.behaviour
|
||||
sys.modules["spade_bdi"] = mock_spade_bdi
|
||||
sys.modules["spade_bdi.bdi"] = mock_spade_bdi.bdi
|
||||
|
||||
# --- Mock the config module to prevent Pydantic ImportError ---
|
||||
mock_config_module = MagicMock()
|
||||
|
||||
# The code under test does `from ... import settings`, so our mock module
|
||||
# must have a `settings` attribute. We'll make it a MagicMock so we can
|
||||
# configure it later in our tests using mocker.patch.
|
||||
mock_config_module.settings = MagicMock()
|
||||
|
||||
sys.modules["control_backend.core.config"] = mock_config_module
|
||||
Reference in New Issue
Block a user