From 9224856919eb86d163acfca298be6b7f5d60361b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 30 Apr 2026 20:33:43 +0200 Subject: [PATCH] Fix flaky dsmr tests broken by Python 3.14.3 asyncio changes (#169431) --- tests/components/dsmr/conftest.py | 8 ++++++++ tests/components/dsmr/test_diagnostics.py | 4 ---- tests/components/dsmr/test_sensor.py | 3 --- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/components/dsmr/conftest.py b/tests/components/dsmr/conftest.py index 769e98f6db4..62fdaa25a28 100644 --- a/tests/components/dsmr/conftest.py +++ b/tests/components/dsmr/conftest.py @@ -25,6 +25,9 @@ def dsmr_connection_fixture() -> Generator[tuple[MagicMock, MagicMock, MagicMock transport = MagicMock(spec=asyncio.Transport) protocol = MagicMock(spec=DSMRProtocol) + closed = asyncio.Event() + protocol.wait_closed = closed.wait + async def connection_factory(*args, **kwargs): """Return mocked out Asyncio classes.""" return (transport, protocol) @@ -42,6 +45,7 @@ def dsmr_connection_fixture() -> Generator[tuple[MagicMock, MagicMock, MagicMock ), ): yield (connection_factory, transport, protocol) + closed.set() @pytest.fixture @@ -53,6 +57,9 @@ def rfxtrx_dsmr_connection_fixture() -> Generator[ transport = MagicMock(spec=asyncio.Transport) protocol = MagicMock(spec=RFXtrxDSMRProtocol) + closed = asyncio.Event() + protocol.wait_closed = closed.wait + async def connection_factory(*args, **kwargs): """Return mocked out Asyncio classes.""" return (transport, protocol) @@ -70,6 +77,7 @@ def rfxtrx_dsmr_connection_fixture() -> Generator[ ), ): yield (connection_factory, transport, protocol) + closed.set() @pytest.fixture diff --git a/tests/components/dsmr/test_diagnostics.py b/tests/components/dsmr/test_diagnostics.py index 457e05a0af8..f2a475097ae 100644 --- a/tests/components/dsmr/test_diagnostics.py +++ b/tests/components/dsmr/test_diagnostics.py @@ -10,7 +10,6 @@ from dsmr_parser.obis_references import ( GAS_METER_READING, ) from dsmr_parser.objects import CosemObject, MBusObject, Telegram -import pytest from syrupy.assertion import SnapshotAssertion from homeassistant.core import HomeAssistant @@ -20,9 +19,6 @@ from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.typing import ClientSessionGenerator -@pytest.mark.xfail( - reason="Flaky due to Python 3.14.3 asyncio changes - see home-assistant/core#162263" -) async def test_diagnostics( hass: HomeAssistant, hass_client: ClientSessionGenerator, diff --git a/tests/components/dsmr/test_sensor.py b/tests/components/dsmr/test_sensor.py index 12db2ed17c0..c67bdbfd444 100644 --- a/tests/components/dsmr/test_sensor.py +++ b/tests/components/dsmr/test_sensor.py @@ -51,9 +51,6 @@ from homeassistant.helpers import entity_registry as er from tests.common import MockConfigEntry, patch -@pytest.mark.xfail( - reason="Flaky due to Python 3.14.3 asyncio changes - see home-assistant/core#162263" -) async def test_default_setup( hass: HomeAssistant, entity_registry: er.EntityRegistry,