Skip to content

Commit 37f5d1f

Browse files
committed
test(message_bus): parametrize makefile-failure cleanup test
Replace the two thin wrappers around _assert_makefile_failure_closes with a single parametrized test so the unix and tcp cases are visible in one place and the helper indirection goes away.
1 parent 2223e04 commit 37f5d1f

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

tests/test_message_bus.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,21 @@ async def _boom(self: MessageBus) -> None:
137137
listener.close()
138138

139139

140-
def _assert_makefile_failure_closes(
140+
@pytest.mark.parametrize(
141+
("transport", "options", "family"),
142+
[
143+
("unix", {"path": "/nope"}, socket.AF_UNIX),
144+
("tcp", {"host": "127.0.0.1", "port": "1"}, socket.AF_INET),
145+
],
146+
ids=["unix", "tcp"],
147+
)
148+
def test_create_socket_for_transport_makefile_failure_closes_socket(
141149
monkeypatch: pytest.MonkeyPatch,
142150
transport: str,
143151
options: dict[str, str],
144152
family: int,
145153
) -> None:
154+
"""A makefile() failure closes the socket before re-raising."""
146155
closed: list[int] = []
147156
real_close = socket.socket.close
148157

@@ -162,24 +171,6 @@ def boom(self: socket.socket, *args: object, **kwargs: object) -> None:
162171
assert family in closed
163172

164173

165-
def test_create_socket_for_transport_unix_makefile_failure_closes_socket(
166-
monkeypatch: pytest.MonkeyPatch,
167-
) -> None:
168-
"""A unix-transport makefile() failure closes the socket before re-raising."""
169-
_assert_makefile_failure_closes(
170-
monkeypatch, "unix", {"path": "/nope"}, socket.AF_UNIX
171-
)
172-
173-
174-
def test_create_socket_for_transport_tcp_makefile_failure_closes_socket(
175-
monkeypatch: pytest.MonkeyPatch,
176-
) -> None:
177-
"""A tcp-transport makefile() failure closes the socket before re-raising."""
178-
_assert_makefile_failure_closes(
179-
monkeypatch, "tcp", {"host": "127.0.0.1", "port": "1"}, socket.AF_INET
180-
)
181-
182-
183174
def test_get_proxy_object_raises_when_proxy_object_class_missing() -> None:
184175
# ProxyObject defaults to None on BaseMessageBus, which is the condition
185176
# under test. Passing an explicit bus_address avoids depending on

0 commit comments

Comments
 (0)