Skip to content

Commit 1b1a0af

Browse files
committed
fix(test): disable C++ extension in unit tests to prevent Windows hang
Unit tests create UdpTransport/TcpTransport objects that, when the C++ extension is present (e.g. in cibuildwheel), instantiate native transports whose start() blocks on Windows. Add an autouse conftest fixture that patches _load_extension to return None and clears the get_ext LRU cache, ensuring unit tests always exercise the pure-Python path regardless of whether the extension is installed. Made-with: Cursor
1 parent 5827f77 commit 1b1a0af

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

tests/unit/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Unit test configuration — force pure-Python path.
2+
3+
Unit tests validate Python-level behaviour and must not depend on
4+
native transport I/O, which may block on some platforms (e.g. Windows).
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from unittest.mock import patch
10+
11+
import pytest
12+
13+
from opensomeip._bridge import get_ext
14+
15+
16+
@pytest.fixture(autouse=True)
17+
def _no_native_ext() -> None: # type: ignore[misc]
18+
"""Ensure ``get_ext()`` returns ``None`` for every unit test."""
19+
get_ext.cache_clear()
20+
with patch("opensomeip._bridge._load_extension", return_value=None):
21+
yield # type: ignore[misc]
22+
get_ext.cache_clear()

tests/unit/test_coverage_gaps.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ def test_send_uses_source_endpoint_when_no_endpoint_or_remote(self) -> None:
231231
t._cpp = mock_cpp
232232
msg = Message(payload=b"test")
233233
msg.source_endpoint = Endpoint("192.168.1.1", 30490)
234-
# Patch to_cpp_* when extension may be unavailable
235234
mock_cpp_msg = MagicMock()
236235
mock_cpp_ep = MagicMock()
237236
with (
@@ -256,10 +255,6 @@ def test_send_large_message_pure_python_path(self) -> None:
256255
tp = __import__("opensomeip.tp", fromlist=["TpManager"]).TpManager
257256
manager = tp(t, mtu=100)
258257
manager.start()
259-
# With ext possibly available, we need to force pure-Python path.
260-
# When ext is None, _cpp is None, so the else branch (lines 112-126) runs.
261-
# When ext is available, the try block runs. To hit pure-Python path,
262-
# we can patch _cpp to None.
263258
with patch.object(manager, "_cpp", None):
264259
msg = Message(
265260
message_id=MessageId(0x1234, 0x0001),

0 commit comments

Comments
 (0)