pytest-mqtt supports testing systems based on MQTT
Project description
pytest-mqtt
About
pytest-mqtt supports testing systems based on MQTT by providing test fixtures for pytest.
It has been conceived for the fine terkin-datalogger and mqttwarn programs.
Details
capmqtt fixture
Capture MQTT messages, using the Paho MQTT Python Client, in the spirit of caplog and capsys. It can also be used to publish MQTT messages.
mosquitto fixture
Provide the Mosquitto MQTT broker as a session-scoped fixture to your test cases.
Usage
@pytest.mark.capmqtt_decode_utf8 def test_mqtt_send_receive(mosquitto, capmqtt): """ Basic send/receive roundtrip, with ASCII text payload (`str`). By using the `capmqtt_decode_utf8` marker, the payloads will also be received as `str`, after decoding them from `utf-8`. """ # Submit two MQTT messages. capmqtt.publish(topic="foo", payload="bar") # Demonstrate the `messages` property. assert capmqtt.messages == [ MqttMessage(topic="foo", payload="bar", userdata=None), ] # Demonstrate the `records` property. assert capmqtt.records == [ ("foo", "bar", None), ]
The capmqtt_decode_utf8 setting can be enabled in three ways.
Session-wide, per pytestconfig option, for example within conftest.py:
@pytest.fixture(scope="session", autouse=True) def configure_capmqtt_decode_utf8(pytestconfig): pytestconfig.option.capmqtt_decode_utf8 = True
On the module level, just say capmqtt_decode_utf8 = True on top of your file.
On individual test cases as a test case marker.
Issues
Both fixtures currently do not support changing the MQTT broker hostname and port number differently than localhost:1883.
The mosquitto fixture currently does not support either authentication or encryption.
capmqtt should be able to capture messages only from specified topics.
Development
git clone https://github.com/mqtt-tools/pytest-mqtt cd pytest-mqtt python3 -m venv .venv source .venv/bin/activate pip install --editable=.[test,develop] poe test
Project information
Contributions
Every kind of contribution, feedback, or patch, is much welcome. Create an issue or submit a patch if you think we should include a new feature, or to report or fix a bug.
Resources
License
The project is licensed under the terms of the MIT license, see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-mqtt-0.1.0.tar.gz
.
File metadata
- Download URL: pytest-mqtt-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/65.3.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58d9ce244ee511f9e9fe213e72e4e0550043a778f470e08964abafa3c5412d09 |
|
MD5 | ed7414536c9ba7e378b802ded3e6d5dc |
|
BLAKE2b-256 | 298945248a20038be3a9a787b78e22ecc3b1f96524d3a1b6c06adcf3e2715b98 |
Provenance
File details
Details for the file pytest_mqtt-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_mqtt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/65.3.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a8e09a1c8d29fd65dd0461ce97e700b3cbe444ae632c720da3a1a4d09e7153f |
|
MD5 | 4025bf2bd57ab96c3e853f02879c2cbd |
|
BLAKE2b-256 | 6aa8eb66e3108f23d02ab58a5c5be8ad2d39e9319291eb571a3e2a5f409d649b |