Warn on undefined variables in templates (#48140)
* Warn on undefined variables in templates * Add test * fix tests * fix tests
This commit is contained in:
parent
863f75e65e
commit
f8755a52c2
4 changed files with 22 additions and 6 deletions
|
@ -1277,8 +1277,7 @@ async def test_repeat_condition_warning(hass, caplog, condition):
|
|||
hass.async_create_task(script_obj.async_run(context=Context()))
|
||||
await asyncio.wait_for(hass.async_block_till_done(), 1)
|
||||
|
||||
assert len(caplog.record_tuples) == 1
|
||||
assert caplog.record_tuples[0][1] == logging.WARNING
|
||||
assert f"Error in '{condition}[0]' evaluation" in caplog.text
|
||||
|
||||
assert len(events) == count
|
||||
|
||||
|
|
|
@ -2497,3 +2497,10 @@ async def test_parse_result(hass):
|
|||
("0011101.00100001010001", "0011101.00100001010001"),
|
||||
):
|
||||
assert template.Template(tpl, hass).async_render() == result
|
||||
|
||||
|
||||
async def test_undefined_variable(hass, caplog):
|
||||
"""Test a warning is logged on undefined variables."""
|
||||
tpl = template.Template("{{ no_such_variable }}", hass)
|
||||
assert tpl.async_render() == ""
|
||||
assert "Template variable warning: no_such_variable is undefined" in caplog.text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue