Enable ruff asyncio event loop blocking detection rules (#120799)

This commit is contained in:
J. Nick Koston
2024-07-04 04:17:57 -05:00
committed by GitHub
parent 43e4223a8e
commit aa74ad0061
3 changed files with 14 additions and 8 deletions

View File

@@ -44,7 +44,7 @@ async def test_protect_loop_debugger_sleep(caplog: pytest.LogCaptureFixture) ->
return_value=frames,
),
):
time.sleep(0)
time.sleep(0) # noqa: ASYNC251
assert "Detected blocking call inside the event loop" not in caplog.text
@@ -71,7 +71,7 @@ async def test_protect_loop_sleep() -> None:
return_value=frames,
),
):
time.sleep(0)
time.sleep(0) # noqa: ASYNC251
async def test_protect_loop_sleep_get_current_frame_raises() -> None:
@@ -97,7 +97,7 @@ async def test_protect_loop_sleep_get_current_frame_raises() -> None:
return_value=frames,
),
):
time.sleep(0)
time.sleep(0) # noqa: ASYNC251
async def test_protect_loop_importlib_import_module_non_integration(
@@ -211,7 +211,7 @@ async def test_protect_loop_open(caplog: pytest.LogCaptureFixture) -> None:
block_async_io.enable()
with (
contextlib.suppress(FileNotFoundError),
open("/proc/does_not_exist", encoding="utf8"),
open("/proc/does_not_exist", encoding="utf8"), # noqa: ASYNC230
):
pass
assert "Detected blocking call to open with args" not in caplog.text
@@ -223,7 +223,7 @@ async def test_protect_open(caplog: pytest.LogCaptureFixture) -> None:
block_async_io.enable()
with (
contextlib.suppress(FileNotFoundError),
open("/config/data_not_exist", encoding="utf8"),
open("/config/data_not_exist", encoding="utf8"), # noqa: ASYNC230
):
pass
@@ -253,7 +253,7 @@ async def test_protect_open_path(path: Any, caplog: pytest.LogCaptureFixture) ->
"""Test opening a file by path in the event loop logs."""
with patch.object(block_async_io, "_IN_TESTS", False):
block_async_io.enable()
with contextlib.suppress(FileNotFoundError), open(path, encoding="utf8"):
with contextlib.suppress(FileNotFoundError), open(path, encoding="utf8"): # noqa: ASYNC230
pass
assert "Detected blocking call to open with args" in caplog.text
@@ -336,7 +336,7 @@ async def test_open_calls_ignored_in_tests(caplog: pytest.LogCaptureFixture) ->
block_async_io.enable()
with (
contextlib.suppress(FileNotFoundError),
open("/config/data_not_exist", encoding="utf8"),
open("/config/data_not_exist", encoding="utf8"), # noqa: ASYNC230
):
pass