mirror of
https://github.com/home-assistant/core.git
synced 2026-12-06 05:38:06 -04:00
Fix flaky automation test_shared_context (#184701)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c2c52b2aaa
commit
9cb260ad56
@@ -440,30 +440,28 @@ async def test_shared_context(hass: HomeAssistant, calls: list[ServiceCall]) ->
|
||||
)
|
||||
|
||||
context = Context()
|
||||
first_automation_listener = Mock()
|
||||
event_mock = Mock()
|
||||
|
||||
hass.bus.async_listen("test_event2", first_automation_listener)
|
||||
hass.bus.async_listen(EVENT_AUTOMATION_TRIGGERED, event_mock)
|
||||
first_automation_events = async_capture_events(hass, "test_event2")
|
||||
triggered_events = async_capture_events(hass, EVENT_AUTOMATION_TRIGGERED)
|
||||
hass.bus.async_fire("test_event", context=context)
|
||||
await hass.async_block_till_done()
|
||||
# Event triggers schedule their action with call_soon, so wait for 'bye' as well
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Ensure events was fired
|
||||
assert first_automation_listener.call_count == 1
|
||||
assert event_mock.call_count == 2
|
||||
assert len(first_automation_events) == 1
|
||||
assert len(triggered_events) == 2
|
||||
|
||||
# Verify automation triggered evenet for 'hello' automation
|
||||
args, _ = event_mock.call_args_list[0]
|
||||
first_trigger_context = args[0].context
|
||||
event = triggered_events[0]
|
||||
first_trigger_context = event.context
|
||||
assert first_trigger_context.parent_id == context.id
|
||||
# Ensure event data has all attributes set
|
||||
assert args[0].data.get(ATTR_NAME) is not None
|
||||
assert args[0].data.get(ATTR_ENTITY_ID) is not None
|
||||
assert args[0].data.get(ATTR_SOURCE) is not None
|
||||
assert event.data.get(ATTR_NAME) is not None
|
||||
assert event.data.get(ATTR_ENTITY_ID) is not None
|
||||
assert event.data.get(ATTR_SOURCE) is not None
|
||||
|
||||
# Ensure context set correctly for event fired by 'hello' automation
|
||||
args, _ = first_automation_listener.call_args
|
||||
assert args[0].context is first_trigger_context
|
||||
assert first_automation_events[0].context is first_trigger_context
|
||||
|
||||
# Ensure the 'hello' automation state has the right context
|
||||
state = hass.states.get("automation.hello")
|
||||
@@ -471,13 +469,13 @@ async def test_shared_context(hass: HomeAssistant, calls: list[ServiceCall]) ->
|
||||
assert state.context is first_trigger_context
|
||||
|
||||
# Verify automation triggered evenet for 'bye' automation
|
||||
args, _ = event_mock.call_args_list[1]
|
||||
second_trigger_context = args[0].context
|
||||
event = triggered_events[1]
|
||||
second_trigger_context = event.context
|
||||
assert second_trigger_context.parent_id == first_trigger_context.id
|
||||
# Ensure event data has all attributes set
|
||||
assert args[0].data.get(ATTR_NAME) is not None
|
||||
assert args[0].data.get(ATTR_ENTITY_ID) is not None
|
||||
assert args[0].data.get(ATTR_SOURCE) is not None
|
||||
assert event.data.get(ATTR_NAME) is not None
|
||||
assert event.data.get(ATTR_ENTITY_ID) is not None
|
||||
assert event.data.get(ATTR_SOURCE) is not None
|
||||
|
||||
# Ensure the service call from the second automation
|
||||
# shares the same context
|
||||
|
||||
Reference in New Issue
Block a user