Skip to content

Commit

Permalink
mqtt as optional extra (#902)
Browse files Browse the repository at this point in the history
michaelboulton authored Jan 20, 2024
1 parent 8e44c4b commit 5032a67
Showing 5 changed files with 26 additions and 11 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@ dependencies = [
"PyYAML>=6.0.1,<7",
"jmespath>=1,<2",
"jsonschema>=4,<5",
"paho-mqtt>=1.3.1,<=1.6.1",
"pyjwt>=2.5.0,<3",
"pykwalify>=1.8.0,<2",
"pytest>=7.4,<8",
@@ -103,6 +102,9 @@ dev = [
# "tbump@https://github.com/michaelboulton/tbump/archive/714ba8957a3c84b625608ceca39811ebe56229dc.zip",
]

mqtt = [
"paho-mqtt>=1.3.1,<=1.6.1",
]

[project.scripts]

10 changes: 6 additions & 4 deletions tavern/_core/plugins.py
Original file line number Diff line number Diff line change
@@ -194,11 +194,13 @@ def get_request_type(
keys[p.plugin.request_block_name] = p.plugin.request_type

if len(set(keys) & set(stage)) > 1:
logger.error("Can only specify 1 request type")
raise exceptions.DuplicateKeysError
raise exceptions.DuplicateKeysError(
f"Can only specify 1 request type but got {set(keys)}"
)
elif not list(set(keys) & set(stage)):
logger.error("Need to specify one of '%s'", keys.keys())
raise exceptions.MissingKeysError
raise exceptions.MissingKeysError(
f"Need to specify one of valid request types: '{set(keys.keys())}'"
)

# We've validated that 1 and only 1 is there, so just loop until the first
# one is found
21 changes: 15 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
import yaml

import tavern
import tavern._plugins.mqtt.tavernhook as mqtt_plugin
from tavern._plugins.rest.tavernhook import TavernRestPlugin as rest_plugin


@@ -23,13 +22,23 @@ def set_plugins():
def extension(name, point):
return stevedore.extension.Extension(name, point, point, point)

tavern._core.plugins.load_plugins.plugins = [
plugins = [
extension(
"requests",
rest_plugin,
),
extension(
"paho-mqtt",
mqtt_plugin,
),
]

try:
import tavern._plugins.mqtt.tavernhook as mqtt_plugin
except ImportError:
pass
else:
plugins.append(
extension(
"paho-mqtt",
mqtt_plugin,
)
)

tavern._core.plugins.load_plugins.plugins = plugins
1 change: 1 addition & 0 deletions tox-integration.ini
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ deps =
colorlog
mqtt: fluent-logger
extras =
mqtt: mqtt
grpc: grpc
commands =
; docker compose stop
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ install_command = python -m pip install {opts} {packages} -c constraints.txt
extras =
dev
grpc
mqtt
commands =
{envbindir}/python -m pytest --cov-report term-missing --cov tavern {posargs}

0 comments on commit 5032a67

Please sign in to comment.