diff --git a/pyproject.toml b/pyproject.toml index ecbb1391..593193cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/tavern/_core/plugins.py b/tavern/_core/plugins.py index 8ac2dc0a..9ea40a34 100644 --- a/tavern/_core/plugins.py +++ b/tavern/_core/plugins.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index a770e583..e9a02cc3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tox-integration.ini b/tox-integration.ini index 9a7b7abc..4d5c1857 100644 --- a/tox-integration.ini +++ b/tox-integration.ini @@ -30,6 +30,7 @@ deps = colorlog mqtt: fluent-logger extras = + mqtt: mqtt grpc: grpc commands = ; docker compose stop diff --git a/tox.ini b/tox.ini index aef629ac..c02a6ca0 100644 --- a/tox.ini +++ b/tox.ini @@ -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}