Skip to content

Commit

Permalink
mqtt as optional extra
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelboulton committed Jan 6, 2024
1 parent 18fc014 commit 52b7e6d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 @@ -89,6 +88,9 @@ dev = [
# "tbump@https://github.com/michaelboulton/tbump/archive/714ba8957a3c84b625608ceca39811ebe56229dc.zip",
]

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

[project.scripts]

Expand Down
8 changes: 7 additions & 1 deletion tavern/_core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
significantly if/when a proper plugin system is implemented!
"""
import dataclasses
import importlib.util
import logging
from functools import partial
from typing import Any, List, Mapping, Optional
Expand Down Expand Up @@ -105,7 +106,12 @@ def enabled(current_backend, ext):
ext.name == test_block_config.tavern_internal.backends[current_backend]
)

for backend in ["http", "mqtt"]:
backends = ["http"]

if importlib.util.find_spec("paho.mqtt") is not None:
backends.append("mqtt")

for backend in backends:
namespace = "tavern_{}".format(backend)

manager = stevedore.EnabledExtensionManager(
Expand Down
11 changes: 6 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import yaml

import tavern
import tavern._plugins.mqtt.tavernhook as mqtt_plugin

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


Expand All @@ -28,8 +29,8 @@ def extension(name, point):
"requests",
rest_plugin,
),
extension(
"paho-mqtt",
mqtt_plugin,
),
# extension(
# "paho-mqtt",
# mqtt_plugin,
# ),
]
2 changes: 2 additions & 0 deletions tox-integration.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ isolated_build = True
[testenv]
allowlist_externals =
docker
extras =
mqtt: mqtt
basepython = python3.11
passenv = DOCKER_TLS_VERIFY,DOCKER_HOST,DOCKER_CERT_PATH,DOCKER_BUILDKIT
setenv =
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ allowlist_externals =
install_command = python -m pip install {opts} {packages} -c constraints.txt
extras =
dev
mqtt
commands =
{envbindir}/python -m pytest --cov-report term-missing --cov tavern {posargs}

Expand Down

0 comments on commit 52b7e6d

Please sign in to comment.