Enable Ruff RUF006; Hard reference to asyncio.create_task return value (#88216)

* Enable Ruff RUF006

* Fix test

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Franck Nijhof 2023-02-19 05:05:44 +01:00 committed by GitHub
parent d4376b2041
commit 6cbad61572
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -258,6 +258,7 @@ select = [
"SIM401", # Use get from dict with default instead of an if block
"T20", # flake8-print
"TRY004", # Prefer TypeError exception for invalid type
"RUF006", # Store a reference to the return value of asyncio.create_task
"UP", # pyupgrade
"W", # pycodestyle
]

View file

@ -122,18 +122,21 @@ def test_run_does_not_block_forever_with_shielded_task(hass, tmpdir, caplog):
async def test_unhandled_exception_traceback(hass, caplog):
"""Test an unhandled exception gets a traceback in debug mode."""
raised = asyncio.Event()
async def _unhandled_exception():
raised.set()
raise Exception("This is unhandled")
try:
hass.loop.set_debug(True)
asyncio.create_task(_unhandled_exception())
task = asyncio.create_task(_unhandled_exception())
await raised.wait()
# Delete it without checking result to trigger unhandled exception
del task
finally:
hass.loop.set_debug(False)
await asyncio.sleep(0)
await asyncio.sleep(0)
assert "Task exception was never retrieved" in caplog.text
assert "This is unhandled" in caplog.text
assert "_unhandled_exception" in caplog.text