-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
Fix flaky velbus test #149743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix flaky velbus test #149743
Conversation
|
Hey there @cereal2nd, @brefra, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a flaky test in the Velbus integration by adding sorting to the device registry entries comparison to ensure deterministic test results.
- Adds sorting to device entries comparison to prevent test flakiness due to random ordering
| device_entries = dr.async_entries_for_config_entry( | ||
| device_registry, config_entry.entry_id | ||
| ) | ||
| assert device_entries == snapshot | ||
| assert sorted(device_entries, key=lambda x: list(x.identifiers)[0][1]) == snapshot |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The sorting key lambda x: list(x.identifiers)[0][1] is complex and could be unclear to future maintainers. Consider extracting this into a named function or adding a comment explaining that it sorts by the second element of the first identifier tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding a comment explaining that it sorts by the second element of the first identifier tuple
There's no need to explain that, because that's literally what the lambda does. We should explain why we need to sort though (the order of the list returned by async_entries_for_config_entry is not consistent)
|
The test is still flaky, just sorting the device list is apparently not enough |
|
@cereal2nd @brefra The sorting in the initial commit seems safe, but I'm not sure about the changes in the last commit. Could you have a look please? |
|
I'm merging this now. @cereal2nd @brefra if the solution in the PR is not good, please fix that in a follow-up 👍 |
Proposed change
SSIA
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: