Try to fix RFLink tests broken by Python 3.14.3 asyncio changes#169157
Conversation
Fixes connections failures management in tests
There was a problem hiding this comment.
Pull request overview
This PR aims to restore stability of the rflink test suite under Python 3.14.3 by adjusting the RFLink connection mock’s failure sequencing and ensuring setup-related tasks have fully settled before assertions.
Changes:
- Change the RFLink test connection mock to consume
failuresin left-to-right order. - Update
binary_sensorandsensoravailability tests to use the new failure sequence and add an extraasync_block_till_done()after setup.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tests/components/rflink/test_sensor.py |
Tweaks availability test’s mocked connection failure sequence and waits for setup tasks to settle. |
tests/components/rflink/test_init.py |
Changes mock connection failure consumption order to match “sequence” semantics. |
tests/components/rflink/test_binary_sensor.py |
Tweaks availability test’s mocked connection failure sequence and waits for setup tasks to settle. |
Remove the `xfail` marker and avoid mutating the shared `CONFIG`
Remove the `xfail` marker and avoid mutating the shared `CONFIG`
There was a problem hiding this comment.
Pull request overview
This PR updates the RFLink test suite to be resilient to Python 3.14.3 asyncio scheduling changes by making connection/reconnect behavior deterministic and ensuring the event loop is fully drained before assertions.
Changes:
- Replace the temporary
xfailmarkers by fixing the underlying timing/race in availability tests. - Adjust RFLink connection failure sequencing in the test mock to use left-to-right ordering.
- Avoid mutating the shared
CONFIGdict in availability tests and explicitly setreconnect_intervalunder therflinkconfig key.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/components/rflink/test_sensor.py |
Makes availability test deterministic via config copy, controlled reconnect failure sequence, and additional loop draining. |
tests/components/rflink/test_binary_sensor.py |
Mirrors the sensor availability test fix for binary sensors (config copy + deterministic reconnect behavior). |
tests/components/rflink/test_init.py |
Changes mock connection failure sequencing to consume failures in call order (pop(0)), matching test expectations. |
| CONF_RECONNECT_INTERVAL: 60, | ||
| }, | ||
| } | ||
| failures = [False, True] |
There was a problem hiding this comment.
The short answer is because is how tests must work.
failures is to mock the create_rflink_connection method called during initialization and reconnections:
https://github.com/javicalle/home-assistant/blob/60cd4a999116b3967215481eab5fb1f1fa40d037/tests/components/rflink/test_init.py#L65-L66
In that tests, during the RFLink initialization the connection must be fine (failure=False) and must create the configured entities but state would be unknown.
After the disconnect_callback call, RFLink will try to reconnect but will fail (failure=True) and should make entities unavailable
Not sure how has been working until now this way. That part of tests has been this way for years. It's possible that the accumulation of errors caused the test to work, because after adding the await hass.async_block_till_done() sentence, 3 bugs has been detected:
- the
fail = failures.pop(0) # removes from left to right(maybe not a bug but very confuse at least) - the
failures = [False, True]to manage failures (probablyfailures = [False, True, False]would be better to make explicit the secondawait hass.async_block_till_done()in tests) - the
config[CONF_RECONNECT_INTERVAL] = 60was wrong and must beconfig['rflink'][CONF_RECONNECT_INTERVAL] = 60(fixed in new code)
I hope this answers your questions.
|
So hey, there are 3 other things.
|
|
@joostlek Thanks for your comments, I appreciate it a lot.
In any case, any of these changes should arrive after #161822. I must say that RFLink usually receives very little attention, making it very difficult to implement changes. |
Breaking change
Proposed change
This makes #169074 obsolete by fixing the tests rather than disable them.
During the code tests another bug has been detected and fixed.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: