From 030727b0788deed60a1e2b1f0409a82e0137f129 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 29 Jan 2024 14:24:58 +0100 Subject: [PATCH] Remove deprecated event_loop fixtures in tests (#109048) --- tests/components/config/test_init.py | 2 +- tests/components/fido/test_sensor.py | 2 +- tests/components/geofency/test_init.py | 4 ++-- tests/components/gpslogger/test_init.py | 4 ++-- tests/components/http/test_security_filter.py | 7 +++---- tests/components/locative/test_init.py | 2 +- tests/components/recorder/test_util.py | 2 +- tests/components/traccar/test_init.py | 4 ++-- tests/conftest.py | 8 +++----- tests/test_bootstrap.py | 9 --------- tests/test_core.py | 4 +--- tests/util/test_location.py | 2 +- 12 files changed, 18 insertions(+), 32 deletions(-) diff --git a/tests/components/config/test_init.py b/tests/components/config/test_init.py index 6a95fb8ebda..4dd786edfd1 100644 --- a/tests/components/config/test_init.py +++ b/tests/components/config/test_init.py @@ -3,7 +3,7 @@ from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -async def test_config_setup(hass: HomeAssistant, event_loop) -> None: +async def test_config_setup(hass: HomeAssistant) -> None: """Test it sets up hassbian.""" await async_setup_component(hass, "config", {}) assert "config" in hass.config.components diff --git a/tests/components/fido/test_sensor.py b/tests/components/fido/test_sensor.py index cccea731a2c..81ae54174ca 100644 --- a/tests/components/fido/test_sensor.py +++ b/tests/components/fido/test_sensor.py @@ -40,7 +40,7 @@ class FidoClientMockError(FidoClientMock): raise PyFidoError("Fake Error") -async def test_fido_sensor(event_loop, hass: HomeAssistant) -> None: +async def test_fido_sensor(hass: HomeAssistant) -> None: """Test the Fido number sensor.""" with patch("homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock): config = { diff --git a/tests/components/geofency/test_init.py b/tests/components/geofency/test_init.py index d5ababaee41..2ab2d9cc8bb 100644 --- a/tests/components/geofency/test_init.py +++ b/tests/components/geofency/test_init.py @@ -116,7 +116,7 @@ def mock_dev_track(mock_device_tracker_conf): @pytest.fixture -async def geofency_client(event_loop, hass, hass_client_no_auth): +async def geofency_client(hass, hass_client_no_auth): """Geofency mock client (unauthenticated).""" assert await async_setup_component( @@ -129,7 +129,7 @@ async def geofency_client(event_loop, hass, hass_client_no_auth): @pytest.fixture(autouse=True) -async def setup_zones(event_loop, hass): +async def setup_zones(hass): """Set up Zone config in HA.""" assert await async_setup_component( hass, diff --git a/tests/components/gpslogger/test_init.py b/tests/components/gpslogger/test_init.py index a9fc5312bba..3873695033e 100644 --- a/tests/components/gpslogger/test_init.py +++ b/tests/components/gpslogger/test_init.py @@ -25,7 +25,7 @@ def mock_dev_track(mock_device_tracker_conf): @pytest.fixture -async def gpslogger_client(event_loop, hass, hass_client_no_auth): +async def gpslogger_client(hass, hass_client_no_auth): """Mock client for GPSLogger (unauthenticated).""" assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) @@ -37,7 +37,7 @@ async def gpslogger_client(event_loop, hass, hass_client_no_auth): @pytest.fixture(autouse=True) -async def setup_zones(event_loop, hass): +async def setup_zones(hass): """Set up Zone config in HA.""" assert await async_setup_component( hass, diff --git a/tests/components/http/test_security_filter.py b/tests/components/http/test_security_filter.py index 9e4353d7e61..0cd85b48b06 100644 --- a/tests/components/http/test_security_filter.py +++ b/tests/components/http/test_security_filter.py @@ -1,4 +1,5 @@ """Test security filter middleware.""" +import asyncio from http import HTTPStatus from aiohttp import web @@ -75,7 +76,6 @@ async def test_bad_requests( fail_on_query_string, aiohttp_client: ClientSessionGenerator, caplog: pytest.LogCaptureFixture, - event_loop, ) -> None: """Test request paths that should be filtered.""" app = web.Application() @@ -93,7 +93,7 @@ async def test_bad_requests( man_params = "" http = urllib3.PoolManager() - resp = await event_loop.run_in_executor( + resp = await asyncio.get_running_loop().run_in_executor( None, http.request, "GET", @@ -126,7 +126,6 @@ async def test_bad_requests_with_unsafe_bytes( fail_on_query_string, aiohttp_client: ClientSessionGenerator, caplog: pytest.LogCaptureFixture, - event_loop, ) -> None: """Test request with unsafe bytes in their URLs.""" app = web.Application() @@ -144,7 +143,7 @@ async def test_bad_requests_with_unsafe_bytes( man_params = "" http = urllib3.PoolManager() - resp = await event_loop.run_in_executor( + resp = await asyncio.get_running_loop().run_in_executor( None, http.request, "GET", diff --git a/tests/components/locative/test_init.py b/tests/components/locative/test_init.py index 8861a166bed..7a1e071958d 100644 --- a/tests/components/locative/test_init.py +++ b/tests/components/locative/test_init.py @@ -20,7 +20,7 @@ def mock_dev_track(mock_device_tracker_conf): @pytest.fixture -async def locative_client(event_loop, hass, hass_client): +async def locative_client(hass, hass_client): """Locative mock client.""" assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) await hass.async_block_till_done() diff --git a/tests/components/recorder/test_util.py b/tests/components/recorder/test_util.py index 66daced2ca8..583416834fb 100644 --- a/tests/components/recorder/test_util.py +++ b/tests/components/recorder/test_util.py @@ -99,7 +99,7 @@ def test_validate_or_move_away_sqlite_database( async def test_last_run_was_recently_clean( - event_loop, async_setup_recorder_instance: RecorderInstanceGenerator, tmp_path: Path + async_setup_recorder_instance: RecorderInstanceGenerator, tmp_path: Path ) -> None: """Test we can check if the last recorder run was recently clean.""" config = { diff --git a/tests/components/traccar/test_init.py b/tests/components/traccar/test_init.py index 1ac7adfb549..b85701f9c72 100644 --- a/tests/components/traccar/test_init.py +++ b/tests/components/traccar/test_init.py @@ -25,7 +25,7 @@ def mock_dev_track(mock_device_tracker_conf): @pytest.fixture(name="client") -async def traccar_client(event_loop, hass, hass_client_no_auth): +async def traccar_client(hass, hass_client_no_auth): """Mock client for Traccar (unauthenticated).""" assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) @@ -37,7 +37,7 @@ async def traccar_client(event_loop, hass, hass_client_no_auth): @pytest.fixture(autouse=True) -async def setup_zones(event_loop, hass): +async def setup_zones(hass): """Set up Zone config in HA.""" assert await async_setup_component( hass, diff --git a/tests/conftest.py b/tests/conftest.py index 856213fa60a..2b61cee4e33 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -517,14 +517,13 @@ def hass_fixture_setup() -> list[bool]: @pytest.fixture async def hass( hass_fixture_setup: list[bool], - event_loop: asyncio.AbstractEventLoop, load_registries: bool, hass_storage: dict[str, Any], request: pytest.FixtureRequest, ) -> AsyncGenerator[HomeAssistant, None]: """Create a test instance of Home Assistant.""" - loop = event_loop + loop = asyncio.get_running_loop() hass_fixture_setup.append(True) orig_tz = dt_util.DEFAULT_TIME_ZONE @@ -577,12 +576,11 @@ async def hass( @pytest.fixture -async def stop_hass( - event_loop: asyncio.AbstractEventLoop, -) -> AsyncGenerator[None, None]: +async def stop_hass() -> AsyncGenerator[None, None]: """Make sure all hass are stopped.""" orig_hass = ha.HomeAssistant + event_loop = asyncio.get_running_loop() created = [] def mock_hass(*args): diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index b640d59df44..a899b3b3d6c 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -480,7 +480,6 @@ async def test_setup_hass( mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, caplog: pytest.LogCaptureFixture, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" verbose = Mock() @@ -530,7 +529,6 @@ async def test_setup_hass_takes_longer_than_log_slow_startup( mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, caplog: pytest.LogCaptureFixture, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" verbose = Mock() @@ -569,7 +567,6 @@ async def test_setup_hass_invalid_yaml( mock_mount_local_lib_path: AsyncMock, mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" with patch( @@ -597,7 +594,6 @@ async def test_setup_hass_config_dir_nonexistent( mock_mount_local_lib_path: AsyncMock, mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" mock_ensure_config_exists.return_value = False @@ -624,7 +620,6 @@ async def test_setup_hass_recovery_mode( mock_mount_local_lib_path: AsyncMock, mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" with patch("homeassistant.components.browser.setup") as browser_setup, patch( @@ -659,7 +654,6 @@ async def test_setup_hass_safe_mode( mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, caplog: pytest.LogCaptureFixture, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" with patch("homeassistant.components.browser.setup"), patch( @@ -692,7 +686,6 @@ async def test_setup_hass_recovery_mode_and_safe_mode( mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, caplog: pytest.LogCaptureFixture, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" with patch("homeassistant.components.browser.setup"), patch( @@ -725,7 +718,6 @@ async def test_setup_hass_invalid_core_config( mock_mount_local_lib_path: AsyncMock, mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" with patch("homeassistant.bootstrap.async_notify_setup_error") as mock_notify: @@ -765,7 +757,6 @@ async def test_setup_recovery_mode_if_no_frontend( mock_mount_local_lib_path: AsyncMock, mock_ensure_config_exists: AsyncMock, mock_process_ha_config_upgrade: Mock, - event_loop: asyncio.AbstractEventLoop, ) -> None: """Test we setup recovery mode if frontend didn't load.""" verbose = Mock() diff --git a/tests/test_core.py b/tests/test_core.py index 3fef994b8e8..4136249f993 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1747,9 +1747,7 @@ async def test_bad_timezone_raises_value_error(hass: HomeAssistant) -> None: await hass.config.async_update(time_zone="not_a_timezone") -async def test_start_taking_too_long( - event_loop, caplog: pytest.LogCaptureFixture -) -> None: +async def test_start_taking_too_long(caplog: pytest.LogCaptureFixture) -> None: """Test when async_start takes too long.""" hass = ha.HomeAssistant("/test/ha-config") caplog.set_level(logging.WARNING) diff --git a/tests/util/test_location.py b/tests/util/test_location.py index e998c10e565..d52362d5ee6 100644 --- a/tests/util/test_location.py +++ b/tests/util/test_location.py @@ -33,7 +33,7 @@ async def session(hass): @pytest.fixture -async def raising_session(event_loop): +async def raising_session(): """Return an aioclient session that only fails.""" return Mock(get=Mock(side_effect=aiohttp.ClientError))