Name | pytest-mqtt JSON |
Version |
0.5.0
JSON |
| download |
home_page | None |
Summary | pytest-mqtt supports testing systems based on MQTT |
upload_time | 2025-01-07 01:01:14 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | MIT |
keywords |
mosquitto
mqtt
paho
pytest
testing
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
###########
pytest-mqtt
###########
|
.. start-badges
|status| |license| |pypi-downloads| |pypi-version|
|ci-tests| |ci-coverage| |python-versions|
.. |ci-tests| image:: https://github.com/mqtt-tools/pytest-mqtt/actions/workflows/tests.yml/badge.svg
:target: https://github.com/mqtt-tools/pytest-mqtt/actions/workflows/tests.yml
:alt: CI outcome
.. |ci-coverage| image:: https://codecov.io/gh/mqtt-tools/pytest-mqtt/branch/main/graph/badge.svg
:target: https://codecov.io/gh/mqtt-tools/pytest-mqtt
:alt: Code coverage
.. |pypi-downloads| image:: https://pepy.tech/badge/pytest-mqtt/month
:target: https://pepy.tech/project/pytest-mqtt
:alt: PyPI downloads per month
.. |pypi-version| image:: https://img.shields.io/pypi/v/pytest-mqtt.svg
:target: https://pypi.org/project/pytest-mqtt/
:alt: Package version on PyPI
.. |status| image:: https://img.shields.io/pypi/status/pytest-mqtt.svg
:target: https://pypi.org/project/pytest-mqtt/
:alt: Project status (alpha, beta, stable)
.. |python-versions| image:: https://img.shields.io/pypi/pyversions/pytest-mqtt.svg
:target: https://pypi.org/project/pytest-mqtt/
:alt: Supported Python versions
.. |license| image:: https://img.shields.io/pypi/l/pytest-mqtt.svg
:target: https://github.com/mqtt-tools/pytest-mqtt/blob/main/LICENSE
:alt: Project license
.. end-badges
*****
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.
``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.
MQTT server host and port are configurable via pytest cli arguments:
``--mqtt-host`` and ``--mqtt-port``. Default values are ``localhost``/``1883``.
``mosquitto`` fixture
=====================
Provide the `Mosquitto`_ MQTT broker as a session-scoped fixture to your test
cases.
*****
Usage
*****
::
import pytest
from pytest_mqtt.model import MqttMessage
@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),
]
The ``capmqtt_decode_utf8`` setting can be enabled in three ways.
1. 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
2. On the module level, just say ``capmqtt_decode_utf8 = True`` on top of your file.
3. On individual test cases as a test case marker, using ``@pytest.mark.capmqtt_decode_utf8``.
******
Issues
******
- 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
=========
- `Source code <https://github.com/mqtt-tools/pytest-mqtt>`_
- `Documentation <https://github.com/mqtt-tools/pytest-mqtt>`_
- `Python Package Index (PyPI) <https://pypi.org/project/pytest-mqtt/>`_
License
=======
The project is licensed under the terms of the MIT license, see `LICENSE`_.
.. _Create an issue: https://github.com/mqtt-tools/pytest-mqtt/issues/new
.. _LICENSE: https://github.com/mqtt-tools/pytest-mqtt/blob/main/LICENSE
.. _Mosquitto: https://github.com/eclipse/mosquitto
.. _mqttwarn: https://github.com/mqtt-tools/mqttwarn
.. _Paho MQTT Python Client: https://github.com/eclipse/paho.mqtt.python
.. _terkin-datalogger: https://github.com/hiveeyes/terkin-datalogger/
Raw data
{
"_id": null,
"home_page": null,
"name": "pytest-mqtt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "mosquitto, mqtt, paho, pytest, testing",
"author": null,
"author_email": "Andreas Motl <andreas.motl@panodata.org>, Richard Pobering <richard.pobering@panodata.org>",
"download_url": "https://files.pythonhosted.org/packages/6f/87/33b9e943d95903be427f09210247352523e5065b8b5463f27743f7c4bac8/pytest_mqtt-0.5.0.tar.gz",
"platform": null,
"description": "###########\npytest-mqtt\n###########\n\n|\n\n.. start-badges\n\n|status| |license| |pypi-downloads| |pypi-version|\n\n|ci-tests| |ci-coverage| |python-versions|\n\n.. |ci-tests| image:: https://github.com/mqtt-tools/pytest-mqtt/actions/workflows/tests.yml/badge.svg\n :target: https://github.com/mqtt-tools/pytest-mqtt/actions/workflows/tests.yml\n :alt: CI outcome\n\n.. |ci-coverage| image:: https://codecov.io/gh/mqtt-tools/pytest-mqtt/branch/main/graph/badge.svg\n :target: https://codecov.io/gh/mqtt-tools/pytest-mqtt\n :alt: Code coverage\n\n.. |pypi-downloads| image:: https://pepy.tech/badge/pytest-mqtt/month\n :target: https://pepy.tech/project/pytest-mqtt\n :alt: PyPI downloads per month\n\n.. |pypi-version| image:: https://img.shields.io/pypi/v/pytest-mqtt.svg\n :target: https://pypi.org/project/pytest-mqtt/\n :alt: Package version on PyPI\n\n.. |status| image:: https://img.shields.io/pypi/status/pytest-mqtt.svg\n :target: https://pypi.org/project/pytest-mqtt/\n :alt: Project status (alpha, beta, stable)\n\n.. |python-versions| image:: https://img.shields.io/pypi/pyversions/pytest-mqtt.svg\n :target: https://pypi.org/project/pytest-mqtt/\n :alt: Supported Python versions\n\n.. |license| image:: https://img.shields.io/pypi/l/pytest-mqtt.svg\n :target: https://github.com/mqtt-tools/pytest-mqtt/blob/main/LICENSE\n :alt: Project license\n\n.. end-badges\n\n\n*****\nAbout\n*****\n\n``pytest-mqtt`` supports testing systems based on MQTT by providing test\nfixtures for ``pytest``. It has been conceived for the fine\n`terkin-datalogger`_ and `mqttwarn`_ programs.\n\n``capmqtt`` fixture\n===================\n\nCapture MQTT messages, using the `Paho MQTT Python Client`_, in the spirit of\n``caplog`` and ``capsys``. It can also be used to publish MQTT messages.\n\nMQTT server host and port are configurable via pytest cli arguments:\n``--mqtt-host`` and ``--mqtt-port``. Default values are ``localhost``/``1883``.\n\n``mosquitto`` fixture\n=====================\n\nProvide the `Mosquitto`_ MQTT broker as a session-scoped fixture to your test\ncases.\n\n\n*****\nUsage\n*****\n\n::\n\n import pytest\n from pytest_mqtt.model import MqttMessage\n\n @pytest.mark.capmqtt_decode_utf8\n def test_mqtt_send_receive(mosquitto, capmqtt):\n \"\"\"\n Basic send/receive roundtrip, using text payload (`str`).\n\n By using the `capmqtt_decode_utf8` marker, the message payloads\n will be recorded as `str`, after decoding them from `utf-8`.\n Otherwise, message payloads would be recorded as `bytes`.\n \"\"\"\n\n # Submit a basic MQTT message.\n capmqtt.publish(topic=\"foo\", payload=\"bar\")\n\n # Demonstrate the \"messages\" property.\n # It returns a list of \"MqttMessage\" objects.\n assert capmqtt.messages == [\n MqttMessage(topic=\"foo\", payload=\"bar\", userdata=None),\n ]\n\n # Demonstrate the \"records\" property.\n # It returns tuples of \"(topic, payload, userdata)\".\n assert capmqtt.records == [\n (\"foo\", \"bar\", None),\n ]\n\n\nThe ``capmqtt_decode_utf8`` setting can be enabled in three ways.\n\n\n1. Session-wide, per ``pytestconfig`` option, for example within ``conftest.py``::\n\n @pytest.fixture(scope=\"session\", autouse=True)\n def configure_capmqtt_decode_utf8(pytestconfig):\n pytestconfig.option.capmqtt_decode_utf8 = True\n\n2. On the module level, just say ``capmqtt_decode_utf8 = True`` on top of your file.\n3. On individual test cases as a test case marker, using ``@pytest.mark.capmqtt_decode_utf8``.\n\n\n******\nIssues\n******\n\n- The ``mosquitto`` fixture currently does not support either authentication or\n encryption.\n\n- ``capmqtt`` should be able to capture messages only from specified topics.\n\n\n***********\nDevelopment\n***********\n\n::\n\n git clone https://github.com/mqtt-tools/pytest-mqtt\n cd pytest-mqtt\n python3 -m venv .venv\n source .venv/bin/activate\n pip install --editable=.[test,develop]\n poe test\n\n\n*******************\nProject information\n*******************\n\nContributions\n=============\n\nEvery kind of contribution, feedback, or patch, is much welcome. `Create an\nissue`_ or submit a patch if you think we should include a new feature, or to\nreport or fix a bug.\n\nResources\n=========\n\n- `Source code <https://github.com/mqtt-tools/pytest-mqtt>`_\n- `Documentation <https://github.com/mqtt-tools/pytest-mqtt>`_\n- `Python Package Index (PyPI) <https://pypi.org/project/pytest-mqtt/>`_\n\nLicense\n=======\n\nThe project is licensed under the terms of the MIT license, see `LICENSE`_.\n\n\n.. _Create an issue: https://github.com/mqtt-tools/pytest-mqtt/issues/new\n.. _LICENSE: https://github.com/mqtt-tools/pytest-mqtt/blob/main/LICENSE\n.. _Mosquitto: https://github.com/eclipse/mosquitto\n.. _mqttwarn: https://github.com/mqtt-tools/mqttwarn\n.. _Paho MQTT Python Client: https://github.com/eclipse/paho.mqtt.python\n.. _terkin-datalogger: https://github.com/hiveeyes/terkin-datalogger/\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "pytest-mqtt supports testing systems based on MQTT",
"version": "0.5.0",
"project_urls": {
"changelog": "https://github.com/mqtt-tools/pytest-mqtt/blob/main/CHANGES.rst",
"documentation": "https://github.com/mqtt-tools/pytest-mqtt",
"homepage": "https://github.com/mqtt-tools/pytest-mqtt",
"repository": "https://github.com/mqtt-tools/pytest-mqtt"
},
"split_keywords": [
"mosquitto",
" mqtt",
" paho",
" pytest",
" testing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5c3a2ec7f49d1960417092f6d3c1246dfeba5478a54061d6900bfc72448dade0",
"md5": "d4878a4fb8c0c394de4e715083725eb6",
"sha256": "d97f07623442c5fb7bc3c82f27a249cc880b9c17eb85e28212d6c2d7fe20ba65"
},
"downloads": -1,
"filename": "pytest_mqtt-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d4878a4fb8c0c394de4e715083725eb6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9479,
"upload_time": "2025-01-07T01:01:12",
"upload_time_iso_8601": "2025-01-07T01:01:12.694969Z",
"url": "https://files.pythonhosted.org/packages/5c/3a/2ec7f49d1960417092f6d3c1246dfeba5478a54061d6900bfc72448dade0/pytest_mqtt-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6f8733b9e943d95903be427f09210247352523e5065b8b5463f27743f7c4bac8",
"md5": "6557493769f58129154406432825e911",
"sha256": "0fbf15126c0d11c44e5a88def39df1d03cc984ce06e96c8b05ba5a0504c71b35"
},
"downloads": -1,
"filename": "pytest_mqtt-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "6557493769f58129154406432825e911",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 10890,
"upload_time": "2025-01-07T01:01:14",
"upload_time_iso_8601": "2025-01-07T01:01:14.084927Z",
"url": "https://files.pythonhosted.org/packages/6f/87/33b9e943d95903be427f09210247352523e5065b8b5463f27743f7c4bac8/pytest_mqtt-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-07 01:01:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mqtt-tools",
"github_project": "pytest-mqtt",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pytest-mqtt"
}