-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Allowing pytest cli arguments for host and port
- Loading branch information
Showing
8 changed files
with
48 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2020-2022 Andreas Motl <[email protected]> | ||
# Copyright (c) 2020-2022 Richard Pobering <[email protected]> | ||
# | ||
|
@@ -36,7 +37,10 @@ | |
class Mosquitto(BaseImage): | ||
|
||
name = "mosquitto" | ||
port = 1883 | ||
|
||
def __init__(self, host: str = "localhost", port: int = 1883) -> None: | ||
self.host = host | ||
self.port = port | ||
|
||
def check(self): | ||
# TODO: Add real implementation. | ||
|
@@ -71,16 +75,18 @@ def run(self): | |
mosquitto_image = Mosquitto() | ||
|
||
|
||
def is_mosquitto_running() -> bool: | ||
return probe_tcp_connect("localhost", 1883) | ||
def is_mosquitto_running(host: str, port: int) -> bool: | ||
return probe_tcp_connect(host, port) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def mosquitto(): | ||
def mosquitto(request, mqttcliargs): | ||
|
||
host, port = mqttcliargs | ||
|
||
# Gracefully skip spinning up the Docker container if Mosquitto is already running. | ||
if is_mosquitto_running(): | ||
yield "localhost", 1883 | ||
if is_mosquitto_running(host, port): | ||
yield host, port | ||
return | ||
|
||
# Spin up Mosquitto container. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typing as t | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def mqttcliargs(request) -> t.Tuple[str, int]: | ||
host = request.config.getoption("--mqtt_host", "localhost") | ||
port = int(request.config.getoption("--mqtt_port", 1883)) | ||
yield host, port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def pytest_addoption(parser) -> None: | ||
parser.addoption("--mqtt_host", action="store", default="localhost", help="mqtt host to be connected through") | ||
parser.addoption("--mqtt_port", action="store", default=1883, help="mqtt port to be connected through") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters