Skip to content

Commit

Permalink
Add connected-mqtt-client fixture
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Heinrich <[email protected]>
  • Loading branch information
andistorm committed Mar 7, 2024
1 parent d707559 commit a449ca8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions everest-testing/src/everest/testing/core_utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -116,3 +118,13 @@ 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(mqtt.CallbackAPIVersion.VERSION2, everest_core.everest_uuid)
client.connect(mqtt_server_uri, mqtt_server_port)
client.loop_start()

return client

0 comments on commit a449ca8

Please sign in to comment.