diff --git a/tests/components/ambient_network/test_sensor.py b/tests/components/ambient_network/test_sensor.py index 35aa90ffe05..0acd9d2d33b 100644 --- a/tests/components/ambient_network/test_sensor.py +++ b/tests/components/ambient_network/test_sensor.py @@ -76,7 +76,7 @@ async def test_sensors_disappearing( open_api: OpenAPI, aioambient, config_entry, - caplog, + caplog: pytest.LogCaptureFixture, ) -> None: """Test that we log errors properly.""" diff --git a/tests/components/cloudflare/test_init.py b/tests/components/cloudflare/test_init.py index 2d66d3c8752..9d96b437733 100644 --- a/tests/components/cloudflare/test_init.py +++ b/tests/components/cloudflare/test_init.py @@ -83,7 +83,9 @@ async def test_async_setup_raises_entry_auth_failed( assert flow["context"]["entry_id"] == entry.entry_id -async def test_integration_services(hass: HomeAssistant, cfupdate, caplog) -> None: +async def test_integration_services( + hass: HomeAssistant, cfupdate, caplog: pytest.LogCaptureFixture +) -> None: """Test integration services.""" instance = cfupdate.return_value @@ -144,7 +146,7 @@ async def test_integration_services_with_issue(hass: HomeAssistant, cfupdate) -> async def test_integration_services_with_nonexisting_record( - hass: HomeAssistant, cfupdate, caplog + hass: HomeAssistant, cfupdate, caplog: pytest.LogCaptureFixture ) -> None: """Test integration services.""" instance = cfupdate.return_value @@ -185,7 +187,7 @@ async def test_integration_services_with_nonexisting_record( async def test_integration_update_interval( hass: HomeAssistant, cfupdate, - caplog, + caplog: pytest.LogCaptureFixture, ) -> None: """Test integration update interval.""" instance = cfupdate.return_value diff --git a/tests/components/generic/test_camera.py b/tests/components/generic/test_camera.py index e359ddaca9d..41a97384e27 100644 --- a/tests/components/generic/test_camera.py +++ b/tests/components/generic/test_camera.py @@ -74,7 +74,7 @@ async def test_fetching_url( hass: HomeAssistant, hass_client: ClientSessionGenerator, fakeimgbytes_png, - caplog: pytest.CaptureFixture, + caplog: pytest.LogCaptureFixture, ) -> None: """Test that it fetches the given url.""" hass.states.async_set("sensor.temp", "http://example.com/0a") diff --git a/tests/components/generic_hygrostat/test_humidifier.py b/tests/components/generic_hygrostat/test_humidifier.py index ef7a2c90aa9..eadc1b22527 100644 --- a/tests/components/generic_hygrostat/test_humidifier.py +++ b/tests/components/generic_hygrostat/test_humidifier.py @@ -471,7 +471,7 @@ async def test_sensor_bad_value(hass: HomeAssistant, setup_comp_2) -> None: async def test_sensor_bad_value_twice( - hass: HomeAssistant, setup_comp_2, caplog + hass: HomeAssistant, setup_comp_2, caplog: pytest.LogCaptureFixture ) -> None: """Test sensor that the second bad value is not logged as warning.""" assert hass.states.get(ENTITY).state == STATE_ON diff --git a/tests/components/matrix/test_send_message.py b/tests/components/matrix/test_send_message.py index 47c3e08aa48..0f3a57e90f1 100644 --- a/tests/components/matrix/test_send_message.py +++ b/tests/components/matrix/test_send_message.py @@ -1,5 +1,7 @@ """Test the send_message service.""" +import pytest + from homeassistant.components.matrix import ( ATTR_FORMAT, ATTR_IMAGES, @@ -14,7 +16,11 @@ from tests.components.matrix.conftest import TEST_BAD_ROOM, TEST_JOINABLE_ROOMS async def test_send_message( - hass: HomeAssistant, matrix_bot: MatrixBot, image_path, matrix_events, caplog + hass: HomeAssistant, + matrix_bot: MatrixBot, + image_path, + matrix_events, + caplog: pytest.LogCaptureFixture, ): """Test the send_message service.""" @@ -55,7 +61,10 @@ async def test_send_message( async def test_unsendable_message( - hass: HomeAssistant, matrix_bot: MatrixBot, matrix_events, caplog + hass: HomeAssistant, + matrix_bot: MatrixBot, + matrix_events, + caplog: pytest.LogCaptureFixture, ): """Test the send_message service with an invalid room.""" assert len(matrix_events) == 0 diff --git a/tests/components/nest/test_init.py b/tests/components/nest/test_init.py index 879cedbdd43..ccd99bb2fd6 100644 --- a/tests/components/nest/test_init.py +++ b/tests/components/nest/test_init.py @@ -8,6 +8,7 @@ mode (e.g. yaml, ConfigEntry, etc) however some tests override and just run in relevant modes. """ +from collections.abc import Generator import logging from typing import Any from unittest.mock import patch @@ -48,14 +49,18 @@ def platforms() -> list[str]: @pytest.fixture -def error_caplog(caplog): +def error_caplog( + caplog: pytest.LogCaptureFixture, +) -> Generator[pytest.LogCaptureFixture, None, None]: """Fixture to capture nest init error messages.""" with caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"): yield caplog @pytest.fixture -def warning_caplog(caplog): +def warning_caplog( + caplog: pytest.LogCaptureFixture, +) -> Generator[pytest.LogCaptureFixture, None, None]: """Fixture to capture nest init warning messages.""" with caplog.at_level(logging.WARNING, logger="homeassistant.components.nest"): yield caplog @@ -78,7 +83,9 @@ def failing_subscriber(subscriber_side_effect: Any) -> YieldFixture[FakeSubscrib yield subscriber -async def test_setup_success(hass: HomeAssistant, error_caplog, setup_platform) -> None: +async def test_setup_success( + hass: HomeAssistant, error_caplog: pytest.LogCaptureFixture, setup_platform +) -> None: """Test successful setup.""" await setup_platform() assert not error_caplog.records @@ -109,7 +116,10 @@ async def test_setup_configuration_failure( @pytest.mark.parametrize("subscriber_side_effect", [SubscriberException()]) async def test_setup_susbcriber_failure( - hass: HomeAssistant, caplog, failing_subscriber, setup_base_platform + hass: HomeAssistant, + caplog: pytest.LogCaptureFixture, + failing_subscriber, + setup_base_platform, ) -> None: """Test configuration error.""" await setup_base_platform() @@ -121,7 +131,7 @@ async def test_setup_susbcriber_failure( async def test_setup_device_manager_failure( - hass: HomeAssistant, caplog, setup_base_platform + hass: HomeAssistant, caplog: pytest.LogCaptureFixture, setup_base_platform ) -> None: """Test device manager api failure.""" with ( @@ -161,7 +171,7 @@ async def test_subscriber_auth_failure( @pytest.mark.parametrize("subscriber_id", [(None)]) async def test_setup_missing_subscriber_id( - hass: HomeAssistant, warning_caplog, setup_base_platform + hass: HomeAssistant, warning_caplog: pytest.LogCaptureFixture, setup_base_platform ) -> None: """Test missing subscriber id from configuration.""" await setup_base_platform() @@ -174,7 +184,10 @@ async def test_setup_missing_subscriber_id( @pytest.mark.parametrize("subscriber_side_effect", [(ConfigurationException())]) async def test_subscriber_configuration_failure( - hass: HomeAssistant, error_caplog, setup_base_platform, failing_subscriber + hass: HomeAssistant, + error_caplog: pytest.LogCaptureFixture, + setup_base_platform, + failing_subscriber, ) -> None: """Test configuration error.""" await setup_base_platform() @@ -187,7 +200,7 @@ async def test_subscriber_configuration_failure( @pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS]) async def test_empty_config( - hass: HomeAssistant, error_caplog, config, setup_platform + hass: HomeAssistant, error_caplog: pytest.LogCaptureFixture, config, setup_platform ) -> None: """Test setup is a no-op with not config.""" await setup_platform() diff --git a/tests/components/nws/test_weather.py b/tests/components/nws/test_weather.py index e4f6df0a9bc..b4f4b5155a1 100644 --- a/tests/components/nws/test_weather.py +++ b/tests/components/nws/test_weather.py @@ -122,7 +122,7 @@ async def test_data_caching_error_observation( freezer: FrozenDateTimeFactory, mock_simple_nws, no_sensor, - caplog, + caplog: pytest.LogCaptureFixture, ) -> None: """Test caching of data with errors.""" instance = mock_simple_nws.return_value @@ -165,7 +165,7 @@ async def test_data_caching_error_observation( async def test_no_data_error_observation( - hass: HomeAssistant, mock_simple_nws, no_sensor, caplog + hass: HomeAssistant, mock_simple_nws, no_sensor, caplog: pytest.LogCaptureFixture ) -> None: """Test catching NwsNoDataDrror.""" instance = mock_simple_nws.return_value @@ -183,7 +183,7 @@ async def test_no_data_error_observation( async def test_no_data_error_forecast( - hass: HomeAssistant, mock_simple_nws, no_sensor, caplog + hass: HomeAssistant, mock_simple_nws, no_sensor, caplog: pytest.LogCaptureFixture ) -> None: """Test catching NwsNoDataDrror.""" instance = mock_simple_nws.return_value @@ -203,7 +203,7 @@ async def test_no_data_error_forecast( async def test_no_data_error_forecast_hourly( - hass: HomeAssistant, mock_simple_nws, no_sensor, caplog + hass: HomeAssistant, mock_simple_nws, no_sensor, caplog: pytest.LogCaptureFixture ) -> None: """Test catching NwsNoDataDrror.""" instance = mock_simple_nws.return_value diff --git a/tests/components/ollama/test_init.py b/tests/components/ollama/test_init.py index c296d6de700..d1074226837 100644 --- a/tests/components/ollama/test_init.py +++ b/tests/components/ollama/test_init.py @@ -20,7 +20,11 @@ from tests.common import MockConfigEntry ], ) async def test_init_error( - hass: HomeAssistant, mock_config_entry: MockConfigEntry, caplog, side_effect, error + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + caplog: pytest.LogCaptureFixture, + side_effect, + error, ) -> None: """Test initialization errors.""" with patch( diff --git a/tests/components/openai_conversation/test_init.py b/tests/components/openai_conversation/test_init.py index 773ba3bca06..f03013556c7 100644 --- a/tests/components/openai_conversation/test_init.py +++ b/tests/components/openai_conversation/test_init.py @@ -179,7 +179,11 @@ async def test_generate_image_service_error( ], ) async def test_init_error( - hass: HomeAssistant, mock_config_entry: MockConfigEntry, caplog, side_effect, error + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + caplog: pytest.LogCaptureFixture, + side_effect, + error, ) -> None: """Test initialization errors.""" with patch( diff --git a/tests/components/python_script/test_init.py b/tests/components/python_script/test_init.py index 463d69975b4..03fa73f076e 100644 --- a/tests/components/python_script/test_init.py +++ b/tests/components/python_script/test_init.py @@ -682,7 +682,7 @@ hass.states.set('hello.c', c) ], ) async def test_prohibited_augmented_assignment_operations( - hass: HomeAssistant, case: str, error: str, caplog + hass: HomeAssistant, case: str, error: str, caplog: pytest.LogCaptureFixture ) -> None: """Test that prohibited augmented assignment operations raise an error.""" hass.async_add_executor_job(execute, hass, "aug_assign_prohibited.py", case, {}) diff --git a/tests/components/rflink/test_init.py b/tests/components/rflink/test_init.py index 2f3559c91f7..f901e46aea1 100644 --- a/tests/components/rflink/test_init.py +++ b/tests/components/rflink/test_init.py @@ -417,7 +417,9 @@ async def test_keepalive( ) -async def test_keepalive_2(hass, monkeypatch, caplog): +async def test_keepalive_2( + hass: HomeAssistant, monkeypatch, caplog: pytest.LogCaptureFixture +) -> None: """Validate very short keepalive values.""" keepalive_value = 30 domain = RFLINK_DOMAIN @@ -443,7 +445,9 @@ async def test_keepalive_2(hass, monkeypatch, caplog): ) -async def test_keepalive_3(hass, monkeypatch, caplog): +async def test_keepalive_3( + hass: HomeAssistant, monkeypatch, caplog: pytest.LogCaptureFixture +) -> None: """Validate keepalive=0 value.""" domain = RFLINK_DOMAIN config = { diff --git a/tests/components/ring/test_init.py b/tests/components/ring/test_init.py index ff9229c748f..f4958f8e497 100644 --- a/tests/components/ring/test_init.py +++ b/tests/components/ring/test_init.py @@ -82,7 +82,7 @@ async def test_error_on_setup( hass: HomeAssistant, requests_mock: requests_mock.Mocker, mock_config_entry: MockConfigEntry, - caplog, + caplog: pytest.LogCaptureFixture, error_type, log_msg, ) -> None: @@ -111,7 +111,7 @@ async def test_auth_failure_on_global_update( hass: HomeAssistant, requests_mock: requests_mock.Mocker, mock_config_entry: MockConfigEntry, - caplog, + caplog: pytest.LogCaptureFixture, ) -> None: """Test authentication failure on global data update.""" mock_config_entry.add_to_hass(hass) @@ -139,7 +139,7 @@ async def test_auth_failure_on_device_update( hass: HomeAssistant, requests_mock: requests_mock.Mocker, mock_config_entry: MockConfigEntry, - caplog, + caplog: pytest.LogCaptureFixture, ) -> None: """Test authentication failure on device data update.""" mock_config_entry.add_to_hass(hass) @@ -181,7 +181,7 @@ async def test_error_on_global_update( hass: HomeAssistant, requests_mock: requests_mock.Mocker, mock_config_entry: MockConfigEntry, - caplog, + caplog: pytest.LogCaptureFixture, error_type, log_msg, ) -> None: @@ -222,7 +222,7 @@ async def test_error_on_device_update( hass: HomeAssistant, requests_mock: requests_mock.Mocker, mock_config_entry: MockConfigEntry, - caplog, + caplog: pytest.LogCaptureFixture, error_type, log_msg, ) -> None: diff --git a/tests/components/ring/test_sensor.py b/tests/components/ring/test_sensor.py index e812b6bcb33..c7c2d64e892 100644 --- a/tests/components/ring/test_sensor.py +++ b/tests/components/ring/test_sensor.py @@ -3,6 +3,7 @@ import logging from freezegun.api import FrozenDateTimeFactory +import pytest import requests_mock from homeassistant.components.ring.const import SCAN_INTERVAL @@ -94,7 +95,7 @@ async def test_only_chime_devices( hass: HomeAssistant, requests_mock: requests_mock.Mocker, freezer: FrozenDateTimeFactory, - caplog, + caplog: pytest.LogCaptureFixture, ) -> None: """Tests the update service works correctly if only chimes are returned.""" await hass.config.async_set_time_zone("UTC") diff --git a/tests/components/songpal/test_media_player.py b/tests/components/songpal/test_media_player.py index ea2812c60f6..2393a5a9086 100644 --- a/tests/components/songpal/test_media_player.py +++ b/tests/components/songpal/test_media_player.py @@ -405,7 +405,9 @@ async def test_disconnected( @pytest.mark.parametrize( ("error_code", "swallow"), [(ERROR_REQUEST_RETRY, True), (1234, False)] ) -async def test_error_swallowing(hass, caplog, service, error_code, swallow): +async def test_error_swallowing( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture, service, error_code, swallow +) -> None: """Test swallowing specific errors on turn_on and turn_off.""" mocked_device = _create_mocked_device() entry = MockConfigEntry(domain=songpal.DOMAIN, data=CONF_DATA) diff --git a/tests/components/template/conftest.py b/tests/components/template/conftest.py index eccb7bc450d..b400d443be7 100644 --- a/tests/components/template/conftest.py +++ b/tests/components/template/conftest.py @@ -15,7 +15,9 @@ def calls(hass: HomeAssistant) -> list[ServiceCall]: @pytest.fixture -async def start_ha(hass, count, domain, config, caplog): +async def start_ha( + hass: HomeAssistant, count, domain, config, caplog: pytest.LogCaptureFixture +): """Do setup of integration.""" with assert_setup_component(count, domain): assert await async_setup_component( @@ -30,6 +32,6 @@ async def start_ha(hass, count, domain, config, caplog): @pytest.fixture -async def caplog_setup_text(caplog): +async def caplog_setup_text(caplog: pytest.LogCaptureFixture) -> str: """Return setup log of integration.""" return caplog.text diff --git a/tests/components/thread/test_dataset_store.py b/tests/components/thread/test_dataset_store.py index a0d85fc6cea..621867ae9cd 100644 --- a/tests/components/thread/test_dataset_store.py +++ b/tests/components/thread/test_dataset_store.py @@ -213,7 +213,9 @@ async def test_add_bad_dataset(hass: HomeAssistant, dataset, error) -> None: await dataset_store.async_add_dataset(hass, "test", dataset) -async def test_update_dataset_newer(hass: HomeAssistant, caplog) -> None: +async def test_update_dataset_newer( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test updating a dataset.""" await dataset_store.async_add_dataset(hass, "test", DATASET_1) await dataset_store.async_add_dataset(hass, "test", DATASET_1_LARGER_TIMESTAMP) @@ -232,7 +234,9 @@ async def test_update_dataset_newer(hass: HomeAssistant, caplog) -> None: ) -async def test_update_dataset_older(hass: HomeAssistant, caplog) -> None: +async def test_update_dataset_older( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test updating a dataset.""" await dataset_store.async_add_dataset(hass, "test", DATASET_1_LARGER_TIMESTAMP) await dataset_store.async_add_dataset(hass, "test", DATASET_1) @@ -354,7 +358,7 @@ async def test_loading_datasets_from_storage( async def test_migrate_drop_bad_datasets( - hass: HomeAssistant, hass_storage: dict[str, Any], caplog + hass: HomeAssistant, hass_storage: dict[str, Any], caplog: pytest.LogCaptureFixture ) -> None: """Test migrating the dataset store when the store has bad datasets.""" hass_storage[dataset_store.STORAGE_KEY] = { @@ -398,7 +402,7 @@ async def test_migrate_drop_bad_datasets( async def test_migrate_drop_bad_datasets_preferred( - hass: HomeAssistant, hass_storage: dict[str, Any], caplog + hass: HomeAssistant, hass_storage: dict[str, Any], caplog: pytest.LogCaptureFixture ) -> None: """Test migrating the dataset store when the store has bad datasets.""" hass_storage[dataset_store.STORAGE_KEY] = { @@ -429,7 +433,7 @@ async def test_migrate_drop_bad_datasets_preferred( async def test_migrate_drop_duplicate_datasets( - hass: HomeAssistant, hass_storage: dict[str, Any], caplog + hass: HomeAssistant, hass_storage: dict[str, Any], caplog: pytest.LogCaptureFixture ) -> None: """Test migrating the dataset store when the store has duplicated datasets.""" hass_storage[dataset_store.STORAGE_KEY] = { @@ -466,7 +470,7 @@ async def test_migrate_drop_duplicate_datasets( async def test_migrate_drop_duplicate_datasets_2( - hass: HomeAssistant, hass_storage: dict[str, Any], caplog + hass: HomeAssistant, hass_storage: dict[str, Any], caplog: pytest.LogCaptureFixture ) -> None: """Test migrating the dataset store when the store has duplicated datasets.""" hass_storage[dataset_store.STORAGE_KEY] = { @@ -503,7 +507,7 @@ async def test_migrate_drop_duplicate_datasets_2( async def test_migrate_drop_duplicate_datasets_preferred( - hass: HomeAssistant, hass_storage: dict[str, Any], caplog + hass: HomeAssistant, hass_storage: dict[str, Any], caplog: pytest.LogCaptureFixture ) -> None: """Test migrating the dataset store when the store has duplicated datasets.""" hass_storage[dataset_store.STORAGE_KEY] = { @@ -540,7 +544,7 @@ async def test_migrate_drop_duplicate_datasets_preferred( async def test_migrate_set_default_border_agent_id( - hass: HomeAssistant, hass_storage: dict[str, Any], caplog + hass: HomeAssistant, hass_storage: dict[str, Any], caplog: pytest.LogCaptureFixture ) -> None: """Test migrating the dataset store adds default border agent.""" hass_storage[dataset_store.STORAGE_KEY] = { diff --git a/tests/components/tplink/test_init.py b/tests/components/tplink/test_init.py index b8f623ac6dc..481a9e0e2b3 100644 --- a/tests/components/tplink/test_init.py +++ b/tests/components/tplink/test_init.py @@ -213,7 +213,7 @@ async def test_config_entry_device_config_invalid( hass: HomeAssistant, mock_discovery: AsyncMock, mock_connect: AsyncMock, - caplog, + caplog: pytest.LogCaptureFixture, ) -> None: """Test that an invalid device config logs an error and loads the config entry.""" entry_data = copy.deepcopy(CREATE_ENTRY_DATA_AUTH) diff --git a/tests/components/zha/test_cluster_handlers.py b/tests/components/zha/test_cluster_handlers.py index ca21b74e106..cc9fb8d1918 100644 --- a/tests/components/zha/test_cluster_handlers.py +++ b/tests/components/zha/test_cluster_handlers.py @@ -839,7 +839,9 @@ async def test_configure_reporting(hass: HomeAssistant, endpoint) -> None: ] -async def test_invalid_cluster_handler(hass: HomeAssistant, caplog) -> None: +async def test_invalid_cluster_handler( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test setting up a cluster handler that fails to match properly.""" class TestZigbeeClusterHandler(cluster_handlers.ClusterHandler): @@ -881,7 +883,9 @@ async def test_invalid_cluster_handler(hass: HomeAssistant, caplog) -> None: assert "missing_attr" in caplog.text -async def test_standard_cluster_handler(hass: HomeAssistant, caplog) -> None: +async def test_standard_cluster_handler( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test setting up a cluster handler that matches a standard cluster.""" class TestZigbeeClusterHandler(ColorClusterHandler): @@ -916,7 +920,9 @@ async def test_standard_cluster_handler(hass: HomeAssistant, caplog) -> None: ) -async def test_quirk_id_cluster_handler(hass: HomeAssistant, caplog) -> None: +async def test_quirk_id_cluster_handler( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test setting up a cluster handler that matches a standard cluster.""" class TestZigbeeClusterHandler(ColorClusterHandler): diff --git a/tests/components/zha/test_init.py b/tests/components/zha/test_init.py index 70ba88ee6e7..4d4956d3978 100644 --- a/tests/components/zha/test_init.py +++ b/tests/components/zha/test_init.py @@ -233,7 +233,7 @@ async def test_zha_retry_unique_ids( config_entry: MockConfigEntry, zigpy_device_mock, mock_zigpy_connect: ControllerApplication, - caplog, + caplog: pytest.LogCaptureFixture, ) -> None: """Test that ZHA retrying creates unique entity IDs."""