Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mqtt as optional extra #902

Merged
merged 9 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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,<7.3",
Expand Down Expand Up @@ -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]

Expand Down
10 changes: 6 additions & 4 deletions tavern/_core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Up @@ -30,6 +30,7 @@ deps =
colorlog
mqtt: fluent-logger
extras =
mqtt: mqtt
grpc: grpc
commands =
; docker compose stop
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down