Warn on undefined variables in templates (#48140)

* Warn on undefined variables in templates

* Add test

* fix tests

* fix tests
This commit is contained in:
Erik Montnemery 2021-03-20 15:16:04 +01:00 committed by GitHub
parent 863f75e65e
commit f8755a52c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 6 deletions

View file

@ -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

View file

@ -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