mqtt-tools / pytest-mqtt

pytest-mqtt supports testing systems based on MQTT.
MIT License
9 stars 2 forks source link

Issue(s) with usage example: fixture 'mqtt_settings' not found #20

Closed aaronkurz closed 5 months ago

aaronkurz commented 6 months ago

I am encountering issues when trying to execute the basic example.

I am running pytest with this test:

from pytest_mqtt.model import MqttMessage
import pytest

@pytest.mark.capmqtt_decode_utf8
def test_mqtt_send_receive(mosquitto, capmqtt):
    """
    Basic send/receive roundtrip, using text payload (`str`).

    By using the `capmqtt_decode_utf8` marker, the message payloads
    will be recorded as `str`, after decoding them from `utf-8`.
    Otherwise, message payloads would be recorded as `bytes`.
    """
    # Submit a basic MQTT message.
    capmqtt.publish(topic="foo", payload="bar")

    # Demonstrate the "messages" property.
    # It returns a list of "MqttMessage" objects.
    assert capmqtt.messages == [
        MqttMessage(topic="foo", payload="bar", userdata=None),
    ]

    # Demonstrate the "records" property.
    # It returns tuples of "(topic, payload, userdata)".
    assert capmqtt.records == [
        ("foo", "bar", None),
    ]

However, I get the error

file /home/aaron/Developer/factory-activity-detection/mqtt_xes/venv/lib/python3.10/site-packages/pytest_mqtt/mosquitto.py, line 83
  @pytest.fixture(scope="session")
  def mosquitto(mqtt_settings: MqttSettings):
E       fixture 'mqtt_settings' not found

How can I fix this issue?

Furthermore, I noticed that import pytest is missing for the basic usage example.

amotl commented 5 months ago

Dear Aaron,

thanks a stack for your report.

It looks like the most recent release is bogus in this regard. I just observed the same error over here, coming from a Dependabot patch.

We will need to look into the issue, and fix it. Apologies for the hiccup, can you work around it by downgrading to the previous version in the meanwhile?

With kind regards, Andreas.

amotl commented 5 months ago

Hi. We just yanked the release 0.4.0 from PyPI, and there is a patch now, intending to fix the problem.

Apologies for the delay, release 0.4.1 is upcoming.

amotl commented 5 months ago

pytest-mqtt 0.4.1 has been released and verified on behalf of https://github.com/daq-tools/lorrystream/pull/95. Closing this. Thanks again.

amotl commented 5 months ago

Furthermore, I noticed that import pytest is missing for the basic usage example.

Thank you. Fixed with 3e410fb2cff.