pytest-mqtt 0.6.2.dev0__tar.gz → 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-mqtt
3
- Version: 0.6.2.dev0
3
+ Version: 0.7.1
4
4
  Summary: pytest-mqtt supports testing systems based on MQTT
5
5
  Author-email: Andreas Motl <andreas.motl@panodata.org>, Richard Pobering <richard.pobering@panodata.org>
6
6
  Project-URL: changelog, https://github.com/mqtt-tools/pytest-mqtt/blob/main/CHANGES.rst
@@ -31,6 +31,8 @@ Classifier: Programming Language :: Python :: 3.10
31
31
  Classifier: Programming Language :: Python :: 3.11
32
32
  Classifier: Programming Language :: Python :: 3.12
33
33
  Classifier: Programming Language :: Python :: 3.13
34
+ Classifier: Programming Language :: Python :: 3.14
35
+ Classifier: Programming Language :: Python :: 3.15
34
36
  Classifier: Topic :: Communications
35
37
  Classifier: Topic :: Education
36
38
  Classifier: Topic :: Home Automation
@@ -51,18 +53,17 @@ Requires-Dist: importlib-metadata; python_version < "3.8"
51
53
  Requires-Dist: paho-mqtt<3
52
54
  Requires-Dist: pytest-docker-fixtures<2
53
55
  Provides-Extra: develop
54
- Requires-Dist: mypy<1.20; extra == "develop"
56
+ Requires-Dist: mypy<2.4; extra == "develop"
55
57
  Requires-Dist: poethepoet<1; extra == "develop"
56
58
  Requires-Dist: pyproject-fmt<3; extra == "develop"
57
- Requires-Dist: ruff<0.15; extra == "develop"
59
+ Requires-Dist: ruff==0.17.*; extra == "develop"
58
60
  Requires-Dist: validate-pyproject<1; extra == "develop"
59
61
  Provides-Extra: release
60
62
  Requires-Dist: build<2; extra == "release"
61
- Requires-Dist: twine<7; extra == "release"
63
+ Requires-Dist: twine<8; extra == "release"
62
64
  Provides-Extra: test
63
65
  Requires-Dist: coverage<8; extra == "test"
64
- Requires-Dist: pytest<9; extra == "test"
65
- Requires-Dist: pytest-fixture-order<1; extra == "test"
66
+ Requires-Dist: pytest<10; extra == "test"
66
67
  Requires-Dist: pytest-httpserver<2; extra == "test"
67
68
  Requires-Dist: pytest-ordering<1; extra == "test"
68
69
  Dynamic: license-file
@@ -103,7 +104,7 @@ pytest-mqtt
103
104
  :target: https://pypi.org/project/pytest-mqtt/
104
105
  :alt: Supported Python versions
105
106
 
106
- .. |license| image:: https://img.shields.io/pypi/l/pytest-mqtt.svg
107
+ .. |license| image:: https://img.shields.io/badge/license-MIT-green.svg
107
108
  :target: https://github.com/mqtt-tools/pytest-mqtt/blob/main/LICENSE
108
109
  :alt: Project license
109
110
 
@@ -130,6 +131,10 @@ MQTT server host and port are configurable via pytest cli arguments:
130
131
  You may additionally specify a username and password for connecting to the broker with:
131
132
  ``--mqtt-username`` and ``--mqtt-password``. Default values are ``guest``/``guest``.
132
133
 
134
+ By default, the test fixture subscribes to all topics, listening on ``#``. This can be
135
+ disabled with the ``--no-subscribe-all`` option. You can then subscribe to the topics
136
+ you are interested in within each test using ``capmqtt.mqtt_client.client.subscribe(cpe.info)``.
137
+
133
138
  ``mosquitto`` fixture
134
139
  =====================
135
140
 
@@ -34,7 +34,7 @@ pytest-mqtt
34
34
  :target: https://pypi.org/project/pytest-mqtt/
35
35
  :alt: Supported Python versions
36
36
 
37
- .. |license| image:: https://img.shields.io/pypi/l/pytest-mqtt.svg
37
+ .. |license| image:: https://img.shields.io/badge/license-MIT-green.svg
38
38
  :target: https://github.com/mqtt-tools/pytest-mqtt/blob/main/LICENSE
39
39
  :alt: Project license
40
40
 
@@ -61,6 +61,10 @@ MQTT server host and port are configurable via pytest cli arguments:
61
61
  You may additionally specify a username and password for connecting to the broker with:
62
62
  ``--mqtt-username`` and ``--mqtt-password``. Default values are ``guest``/``guest``.
63
63
 
64
+ By default, the test fixture subscribes to all topics, listening on ``#``. This can be
65
+ disabled with the ``--no-subscribe-all`` option. You can then subscribe to the topics
66
+ you are interested in within each test using ``capmqtt.mqtt_client.client.subscribe(cpe.info)``.
67
+
64
68
  ``mosquitto`` fixture
65
69
  =====================
66
70
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  [project]
8
8
  name = "pytest-mqtt"
9
- version = "0.6.2.dev0"
9
+ version = "0.7.1"
10
10
  description = "pytest-mqtt supports testing systems based on MQTT"
11
11
  readme = "README.rst"
12
12
  keywords = [ "mosquitto", "mqtt", "paho", "pytest", "testing" ]
@@ -39,6 +39,8 @@ classifiers = [
39
39
  "Programming Language :: Python :: 3.11",
40
40
  "Programming Language :: Python :: 3.12",
41
41
  "Programming Language :: Python :: 3.13",
42
+ "Programming Language :: Python :: 3.14",
43
+ "Programming Language :: Python :: 3.15",
42
44
  "Topic :: Communications",
43
45
  "Topic :: Education",
44
46
  "Topic :: Home Automation",
@@ -61,20 +63,19 @@ dependencies = [
61
63
  ]
62
64
 
63
65
  optional-dependencies.develop = [
64
- "mypy<1.20",
66
+ "mypy<2.4",
65
67
  "poethepoet<1",
66
68
  "pyproject-fmt<3",
67
- "ruff<0.15",
69
+ "ruff==0.17.*",
68
70
  "validate-pyproject<1",
69
71
  ]
70
72
  optional-dependencies.release = [
71
73
  "build<2",
72
- "twine<7",
74
+ "twine<8",
73
75
  ]
74
76
  optional-dependencies.test = [
75
77
  "coverage<8",
76
- "pytest<9",
77
- "pytest-fixture-order<1",
78
+ "pytest<10",
78
79
  "pytest-httpserver<2",
79
80
  "pytest-ordering<1",
80
81
  ]
@@ -100,7 +101,7 @@ line-length = 120
100
101
  [tool.pytest.ini_options]
101
102
  minversion = "2.0"
102
103
  addopts = """
103
- -rfEX -p pytester --strict-markers --verbosity=3
104
+ -rfEXS -p pytester --strict-markers --verbosity=3
104
105
  """
105
106
  log_level = "DEBUG"
106
107
  log_cli_level = "DEBUG"
@@ -1,7 +1,7 @@
1
1
  try:
2
- from importlib.metadata import PackageNotFoundError, version # noqa
2
+ from importlib.metadata import PackageNotFoundError, version
3
3
  except ImportError: # pragma: no cover
4
- from importlib_metadata import PackageNotFoundError, version # type: ignore[no-redef] # noqa
4
+ from importlib_metadata import PackageNotFoundError, version # type: ignore[no-redef]
5
5
 
6
6
  from .model import MqttMessage # noqa: F401
7
7
 
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  # Copyright (c) 2020-2022 Andreas Motl <andreas.motl@panodata.org>
3
2
  # Copyright (c) 2020-2022 Richard Pobering <richard.pobering@panodata.org>
4
3
  #
@@ -14,6 +13,8 @@ Source: https://github.com/hiveeyes/terkin-datalogger/blob/0.13.0/test/fixtures/
14
13
  .. _Paho MQTT Python Client: https://github.com/eclipse/paho.mqtt.python
15
14
  """
16
15
 
16
+ from __future__ import annotations
17
+
17
18
  import logging
18
19
  import threading
19
20
  import typing as t
@@ -30,11 +31,12 @@ logger = logging.getLogger(__name__)
30
31
  class MqttClientAdapter(threading.Thread):
31
32
  def __init__(
32
33
  self,
33
- on_message_callback: t.Optional[t.Callable] = None,
34
+ on_message_callback: t.Callable | None = None,
34
35
  host: str = "localhost",
35
36
  port: int = 1883,
36
37
  username: str = "guest",
37
38
  password: str = "guest",
39
+ subscribe_all: bool = True,
38
40
  ):
39
41
  super().__init__()
40
42
  self.client: mqtt.Client
@@ -51,6 +53,7 @@ class MqttClientAdapter(threading.Thread):
51
53
  self.port = int(port)
52
54
  self.username = username
53
55
  self.password = password
56
+ self.subscribe_all = subscribe_all
54
57
 
55
58
  self.setup()
56
59
 
@@ -66,7 +69,8 @@ class MqttClientAdapter(threading.Thread):
66
69
 
67
70
  logger.debug("[PYTEST] Connecting to MQTT broker")
68
71
  client.connect(host=self.host, port=self.port)
69
- client.subscribe("#")
72
+ if self.subscribe_all:
73
+ client.subscribe("#")
70
74
 
71
75
  def run(self) -> None:
72
76
  self.client.loop_start()
@@ -99,7 +103,7 @@ class MqttClientAdapter(threading.Thread):
99
103
  def publish(
100
104
  self,
101
105
  topic: str,
102
- payload: t.Union[str, bytes, bytearray, int, float, None],
106
+ payload: str | bytes | bytearray | float | None,
103
107
  **kwargs,
104
108
  ) -> mqtt.MQTTMessageInfo:
105
109
  message_info = self.client.publish(topic, payload, **kwargs)
@@ -112,18 +116,24 @@ class MqttCaptureFixture:
112
116
 
113
117
  def __init__(
114
118
  self,
115
- decode_utf8: t.Optional[bool],
119
+ decode_utf8: bool | None,
116
120
  host: str = "localhost",
117
121
  port: int = 1883,
118
122
  username: str = "guest",
119
123
  password: str = "guest",
124
+ subscribe_all: bool = True,
120
125
  ) -> None:
121
126
  """Creates a new funcarg."""
122
- self._buffer: t.List[MqttMessage] = []
127
+ self._buffer: list[MqttMessage] = []
123
128
  self._decode_utf8: bool = decode_utf8 or False
124
129
 
125
130
  self.mqtt_client = MqttClientAdapter(
126
- on_message_callback=self.on_message, host=host, port=port, username=username, password=password
131
+ on_message_callback=self.on_message,
132
+ host=host,
133
+ port=port,
134
+ username=username,
135
+ password=password,
136
+ subscribe_all=subscribe_all,
127
137
  )
128
138
  self.mqtt_client.start()
129
139
  # time.sleep(0.1)
@@ -148,17 +158,17 @@ class MqttCaptureFixture:
148
158
  self._buffer = []
149
159
 
150
160
  @property
151
- def messages(self) -> t.List[MqttMessage]:
161
+ def messages(self) -> list[MqttMessage]:
152
162
  return self._buffer
153
163
 
154
164
  @property
155
- def records(self) -> t.List[t.Tuple[str, t.Union[str, bytes], t.Union[t.Dict, None]]]:
165
+ def records(self) -> list[tuple[str, str | bytes, dict | None]]:
156
166
  return [(item.topic, item.payload, item.userdata) for item in self._buffer]
157
167
 
158
168
  def publish(
159
169
  self,
160
170
  topic: str,
161
- payload: t.Union[str, bytes, bytearray, int, float, None],
171
+ payload: str | bytes | bytearray | float | None,
162
172
  **kwargs,
163
173
  ) -> mqtt.MQTTMessageInfo:
164
174
  message_info = self.mqtt_client.publish(topic=topic, payload=payload, **kwargs)
@@ -178,6 +188,7 @@ def capmqtt(request, mqtt_settings: MqttSettings):
178
188
 
179
189
  host, port = mqtt_settings.host, mqtt_settings.port
180
190
  username, password = mqtt_settings.username, mqtt_settings.password
191
+ subscribe_all = mqtt_settings.subscribe_all
181
192
 
182
193
  capmqtt_decode_utf8 = (
183
194
  getattr(request.config.option, "capmqtt_decode_utf8", False)
@@ -185,7 +196,12 @@ def capmqtt(request, mqtt_settings: MqttSettings):
185
196
  or request.node.get_closest_marker("capmqtt_decode_utf8") is not None
186
197
  )
187
198
  result = MqttCaptureFixture(
188
- decode_utf8=capmqtt_decode_utf8, host=host, port=port, username=username, password=password
199
+ decode_utf8=capmqtt_decode_utf8,
200
+ host=host,
201
+ port=port,
202
+ username=username,
203
+ password=password,
204
+ subscribe_all=subscribe_all,
189
205
  )
190
206
  delay()
191
207
  yield result
@@ -1,5 +1,6 @@
1
+ from __future__ import annotations
2
+
1
3
  import dataclasses
2
- import typing as t
3
4
 
4
5
 
5
6
  @dataclasses.dataclass
@@ -9,8 +10,8 @@ class MqttMessage:
9
10
  """
10
11
 
11
12
  topic: str
12
- payload: t.Union[str, bytes]
13
- userdata: t.Optional[t.Union[t.Dict, None]]
13
+ payload: str | bytes
14
+ userdata: None | dict
14
15
 
15
16
 
16
17
  @dataclasses.dataclass
@@ -19,3 +20,4 @@ class MqttSettings:
19
20
  port: int
20
21
  username: str
21
22
  password: str
23
+ subscribe_all: bool
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  # Copyright (c) 2020-2022 Andreas Motl <andreas.motl@panodata.org>
4
2
  # Copyright (c) 2020-2022 Richard Pobering <richard.pobering@panodata.org>
5
3
  #
@@ -64,14 +62,16 @@ class Mosquitto(BaseImage):
64
62
  try:
65
63
  docker_client = docker.from_env(version=self.docker_version)
66
64
  docker_url = docker_client.api.base_url
67
- except Exception:
68
- raise ConnectionError("Cannot connect to the Docker daemon. Is the docker daemon running?")
65
+ except Exception as e:
66
+ raise ConnectionError("Cannot connect to the Docker daemon. Is the docker daemon running?") from e
69
67
  try:
70
68
  docker_client.ping()
71
- except Exception:
72
- raise ConnectionError(f"Cannot connect to the Docker daemon at {docker_url}. Is the docker daemon running?")
69
+ except Exception as e:
70
+ raise ConnectionError(
71
+ f"Cannot connect to the Docker daemon at {docker_url}. Is the docker daemon running?"
72
+ ) from e
73
73
  self.pull_image()
74
- return super(Mosquitto, self).run()
74
+ return super().run()
75
75
 
76
76
 
77
77
  mosquitto_image = Mosquitto()
@@ -86,6 +86,9 @@ def pytest_addoption(parser) -> None:
86
86
  parser.addoption("--mqtt-port", action="store", type=int, default=1883, help="MQTT port number")
87
87
  parser.addoption("--mqtt-username", action="store", type=str, default="guest", help="Username for connection")
88
88
  parser.addoption("--mqtt-password", action="store", type=str, default="guest", help="Password for connection")
89
+ parser.addoption(
90
+ "--no-subscribe-all", action="store_false", dest="subscribe_all", help="Do not subscribe to all topics"
91
+ )
89
92
 
90
93
 
91
94
  @pytest.fixture(scope="session")
@@ -95,6 +98,7 @@ def mqtt_settings(pytestconfig) -> MqttSettings:
95
98
  port=pytestconfig.getoption("--mqtt-port"),
96
99
  username=pytestconfig.getoption("--mqtt-username"),
97
100
  password=pytestconfig.getoption("--mqtt-password"),
101
+ subscribe_all=pytestconfig.getoption("subscribe_all"),
98
102
  )
99
103
 
100
104
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-mqtt
3
- Version: 0.6.2.dev0
3
+ Version: 0.7.1
4
4
  Summary: pytest-mqtt supports testing systems based on MQTT
5
5
  Author-email: Andreas Motl <andreas.motl@panodata.org>, Richard Pobering <richard.pobering@panodata.org>
6
6
  Project-URL: changelog, https://github.com/mqtt-tools/pytest-mqtt/blob/main/CHANGES.rst
@@ -31,6 +31,8 @@ Classifier: Programming Language :: Python :: 3.10
31
31
  Classifier: Programming Language :: Python :: 3.11
32
32
  Classifier: Programming Language :: Python :: 3.12
33
33
  Classifier: Programming Language :: Python :: 3.13
34
+ Classifier: Programming Language :: Python :: 3.14
35
+ Classifier: Programming Language :: Python :: 3.15
34
36
  Classifier: Topic :: Communications
35
37
  Classifier: Topic :: Education
36
38
  Classifier: Topic :: Home Automation
@@ -51,18 +53,17 @@ Requires-Dist: importlib-metadata; python_version < "3.8"
51
53
  Requires-Dist: paho-mqtt<3
52
54
  Requires-Dist: pytest-docker-fixtures<2
53
55
  Provides-Extra: develop
54
- Requires-Dist: mypy<1.20; extra == "develop"
56
+ Requires-Dist: mypy<2.4; extra == "develop"
55
57
  Requires-Dist: poethepoet<1; extra == "develop"
56
58
  Requires-Dist: pyproject-fmt<3; extra == "develop"
57
- Requires-Dist: ruff<0.15; extra == "develop"
59
+ Requires-Dist: ruff==0.17.*; extra == "develop"
58
60
  Requires-Dist: validate-pyproject<1; extra == "develop"
59
61
  Provides-Extra: release
60
62
  Requires-Dist: build<2; extra == "release"
61
- Requires-Dist: twine<7; extra == "release"
63
+ Requires-Dist: twine<8; extra == "release"
62
64
  Provides-Extra: test
63
65
  Requires-Dist: coverage<8; extra == "test"
64
- Requires-Dist: pytest<9; extra == "test"
65
- Requires-Dist: pytest-fixture-order<1; extra == "test"
66
+ Requires-Dist: pytest<10; extra == "test"
66
67
  Requires-Dist: pytest-httpserver<2; extra == "test"
67
68
  Requires-Dist: pytest-ordering<1; extra == "test"
68
69
  Dynamic: license-file
@@ -103,7 +104,7 @@ pytest-mqtt
103
104
  :target: https://pypi.org/project/pytest-mqtt/
104
105
  :alt: Supported Python versions
105
106
 
106
- .. |license| image:: https://img.shields.io/pypi/l/pytest-mqtt.svg
107
+ .. |license| image:: https://img.shields.io/badge/license-MIT-green.svg
107
108
  :target: https://github.com/mqtt-tools/pytest-mqtt/blob/main/LICENSE
108
109
  :alt: Project license
109
110
 
@@ -130,6 +131,10 @@ MQTT server host and port are configurable via pytest cli arguments:
130
131
  You may additionally specify a username and password for connecting to the broker with:
131
132
  ``--mqtt-username`` and ``--mqtt-password``. Default values are ``guest``/``guest``.
132
133
 
134
+ By default, the test fixture subscribes to all topics, listening on ``#``. This can be
135
+ disabled with the ``--no-subscribe-all`` option. You can then subscribe to the topics
136
+ you are interested in within each test using ``capmqtt.mqtt_client.client.subscribe(cpe.info)``.
137
+
133
138
  ``mosquitto`` fixture
134
139
  =====================
135
140
 
@@ -8,19 +8,18 @@ dataclasses
8
8
  importlib-metadata
9
9
 
10
10
  [develop]
11
- mypy<1.20
11
+ mypy<2.4
12
12
  poethepoet<1
13
13
  pyproject-fmt<3
14
- ruff<0.15
14
+ ruff==0.17.*
15
15
  validate-pyproject<1
16
16
 
17
17
  [release]
18
18
  build<2
19
- twine<7
19
+ twine<8
20
20
 
21
21
  [test]
22
22
  coverage<8
23
- pytest<9
24
- pytest-fixture-order<1
23
+ pytest<10
25
24
  pytest-httpserver<2
26
25
  pytest-ordering<1
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env python
2
-
3
1
  # This is a shim to hopefully allow GitHub to detect the package.
4
2
  # The build is done with Poetry.
5
3
 
File without changes
File without changes