Fix potentially flaky tests in multiple integrations#155108
Fix potentially flaky tests in multiple integrations#155108
Conversation
Replace multiple consecutive async_block_till_done() calls with single async_block_till_done(wait_background_tasks=True) calls after async_fire_time_changed() in test files. This pattern is more reliable and predictable than calling async_block_till_done() multiple times, which doesn't guarantee proper handling of all async operations and can lead to flaky tests. Affected integrations: - knx: 2 instances in test_init.py - nest: 1 instance in test_media_source.py - openrgb: 3 instances in test_init.py (including one with 3 consecutive calls) - playstation_network: 1 instance in test_image.py - rflink: 2 instances in test_binary_sensor.py - sun: 1 instance in test_init.py - template: 4 instances (1 in test_sensor.py, 3 in test_trigger.py) Total: 14 instances fixed across 7 integrations. Follows the same fix pattern from PR #155095 which addressed similar issues in the openrgb light tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
Pull Request Overview
This PR improves test reliability by replacing multiple consecutive async_block_till_done() calls with single async_block_till_done(wait_background_tasks=True) calls after async_fire_time_changed() operations. This pattern is more robust and predictable, as it explicitly waits for all background tasks to complete rather than requiring multiple iterations.
Key changes:
- Consolidated 14 instances of double/triple
async_block_till_done()calls into single calls withwait_background_tasks=True - Applied changes across 7 integrations (nest, openrgb, playstation_network, rflink, sun, template, knx)
- Follows the established pattern from PR #155095
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/components/template/test_trigger.py | Replaced 3 instances of double async_block_till_done() calls with single calls using wait_background_tasks=True parameter |
| tests/components/template/test_sensor.py | Replaced 1 instance of double async_block_till_done() calls with single call using wait_background_tasks=True parameter |
| tests/components/sun/test_init.py | Replaced 1 instance of double async_block_till_done() calls with single call using wait_background_tasks=True parameter |
| tests/components/rflink/test_binary_sensor.py | Replaced 2 instances of double async_block_till_done() calls with single calls using wait_background_tasks=True parameter |
| tests/components/playstation_network/test_image.py | Replaced 1 instance of double async_block_till_done() calls with single call using wait_background_tasks=True parameter |
| tests/components/openrgb/test_init.py | Replaced 3 instances of multiple async_block_till_done() calls (including one with 3 consecutive calls) with single calls using wait_background_tasks=True parameter |
| tests/components/nest/test_media_source.py | Replaced 1 instance of double async_block_till_done() calls with single call using wait_background_tasks=True parameter |
| tests/components/knx/test_init.py | Replaced 2 instances of double async_block_till_done() calls with single calls using wait_background_tasks=True parameter |
| await hass.async_block_till_done(wait_background_tasks=True) | ||
| await knx.assert_no_telegram() | ||
|
|
||
| freezer.tick(timedelta(minutes=1)) # 60 minutes passed | ||
| async_fire_time_changed(hass) | ||
| await hass.async_block_till_done() | ||
| await hass.async_block_till_done() | ||
| await hass.async_block_till_done(wait_background_tasks=True) |
There was a problem hiding this comment.
This isn't waiting for a HomeAssistant background task, but an xknx internal background task 😬
There was a problem hiding this comment.
yes, I removed this one... not sure why it is still in the branch. I swear I removed it.
allenporter
left a comment
There was a problem hiding this comment.
Nest change looks good.
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Proposed change
Replace multiple consecutive async_block_till_done() calls with single async_block_till_done(wait_background_tasks=True) calls after async_fire_time_changed() in test files.
This pattern is more reliable and predictable than calling async_block_till_done() multiple times, which doesn't guarantee proper handling of all async operations and can lead to flaky tests.
Affected integrations:
Total: 14 instances fixed across 7 integrations.
Follows the same fix pattern from PR #155095 which addressed similar issues in the openrgb light tests.
🤖 Generated with Claude Code
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: