diff --git a/everest-testing/setup.cfg b/everest-testing/setup.cfg index 779fb14b..99a3bbc5 100644 --- a/everest-testing/setup.cfg +++ b/everest-testing/setup.cfg @@ -17,7 +17,7 @@ install_requires = pytest pytest-asyncio python-dateutil - paho-mqtt + paho-mqtt ==1.6.1 pyftpdlib ocpp websockets diff --git a/everest-testing/src/everest/testing/core_utils/fixtures.py b/everest-testing/src/everest/testing/core_utils/fixtures.py index dc65c808..c2271552 100644 --- a/everest-testing/src/everest/testing/core_utils/fixtures.py +++ b/everest-testing/src/everest/testing/core_utils/fixtures.py @@ -4,6 +4,8 @@ from typing import Optional import pytest +import os +import paho.mqtt.client as mqtt from ._configuration.everest_configuration_strategies.everest_configuration_strategy import \ EverestConfigAdjustmentStrategy @@ -116,3 +118,15 @@ def test_controller(request, tmp_path, everest_core) -> EverestTestController: # FIXME (aw): proper life time management, shouldn't the fixure start and stop? test_controller.stop() + +@pytest.fixture +def connected_mqtt_client(everest_core: EverestCore) -> mqtt.Client: + mqtt_server_uri = os.environ.get("MQTT_SERVER_ADDRESS", "127.0.0.1") + mqtt_server_port = int(os.environ.get("MQTT_SERVER_PORT", "1883")) + client = mqtt.Client(everest_core.everest_uuid) + client.connect(mqtt_server_uri, mqtt_server_port) + client.loop_start() + + yield client + + client.loop_stop()