diff --git a/tests/components/airvisual/conftest.py b/tests/components/airvisual/conftest.py index c85d6e90c4b..f6c1619d6d3 100644 --- a/tests/components/airvisual/conftest.py +++ b/tests/components/airvisual/conftest.py @@ -141,4 +141,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_pyairvisual): """Define a fixture to set up airvisual.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield diff --git a/tests/components/aladdin_connect/conftest.py b/tests/components/aladdin_connect/conftest.py index ee9afed9823..250548e7ef2 100644 --- a/tests/components/aladdin_connect/conftest.py +++ b/tests/components/aladdin_connect/conftest.py @@ -40,4 +40,4 @@ def fixture_mock_aladdinconnect_api(): mock_opener.open_door = AsyncMock(return_value=True) mock_opener.close_door = AsyncMock(return_value=True) - yield mock_opener + return mock_opener diff --git a/tests/components/ambient_station/conftest.py b/tests/components/ambient_station/conftest.py index 594458436e7..aa849922b34 100644 --- a/tests/components/ambient_station/conftest.py +++ b/tests/components/ambient_station/conftest.py @@ -60,4 +60,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aioambient): """Define a fixture to set up ambient_station.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield diff --git a/tests/components/apple_tv/conftest.py b/tests/components/apple_tv/conftest.py index f3c3148fe72..b516cc5e71e 100644 --- a/tests/components/apple_tv/conftest.py +++ b/tests/components/apple_tv/conftest.py @@ -92,7 +92,7 @@ def full_device(mock_scan, dmap_pin): airplay_service(), ) ) - yield mock_scan + return mock_scan @pytest.fixture @@ -112,7 +112,7 @@ def mrp_device(mock_scan): ), ] ) - yield mock_scan + return mock_scan @pytest.fixture @@ -132,7 +132,7 @@ def airplay_with_disabled_mrp(mock_scan): ), ) ) - yield mock_scan + return mock_scan @pytest.fixture @@ -152,7 +152,7 @@ def dmap_device(mock_scan): ), ) ) - yield mock_scan + return mock_scan @pytest.fixture @@ -172,7 +172,7 @@ def dmap_device_with_credentials(mock_scan): ), ) ) - yield mock_scan + return mock_scan @pytest.fixture @@ -187,7 +187,7 @@ def airplay_device_with_password(mock_scan): ), ) ) - yield mock_scan + return mock_scan @pytest.fixture @@ -206,4 +206,4 @@ def dmap_with_requirement(mock_scan, pairing_requirement): ), ) ) - yield mock_scan + return mock_scan diff --git a/tests/components/axis/conftest.py b/tests/components/axis/conftest.py index 31d20c0e7df..ccaa983c5fd 100644 --- a/tests/components/axis/conftest.py +++ b/tests/components/axis/conftest.py @@ -154,7 +154,7 @@ def default_request_fixture(respx_mock): ) respx.post(f"{path}/local/vmd/control.cgi").respond(json=VMD4_RESPONSE) - yield __mock_default_requests + return __mock_default_requests @pytest.fixture @@ -187,7 +187,7 @@ async def prep_config_entry_fixture(hass, config_entry, setup_default_vapix_requ await hass.async_block_till_done() return config_entry - yield __mock_setup_config_entry + return __mock_setup_config_entry @pytest.fixture(name="setup_config_entry") @@ -195,7 +195,7 @@ async def setup_config_entry_fixture(hass, config_entry, setup_default_vapix_req """Define a fixture to set up Axis network device.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield config_entry + return config_entry # RTSP fixtures @@ -283,7 +283,7 @@ def mock_rtsp_event(mock_axis_rtspclient): mock_axis_rtspclient(data=event.encode("utf-8")) - yield send_event + return send_event @pytest.fixture(autouse=True) @@ -295,4 +295,4 @@ def mock_rtsp_signal_state(mock_axis_rtspclient): signal = Signal.PLAYING if connected else Signal.FAILED mock_axis_rtspclient(state=signal) - yield send_signal + return send_signal diff --git a/tests/components/blebox/test_config_flow.py b/tests/components/blebox/test_config_flow.py index 265b7128a55..88f24579e54 100644 --- a/tests/components/blebox/test_config_flow.py +++ b/tests/components/blebox/test_config_flow.py @@ -84,7 +84,7 @@ def product_class_mock_fixture(): """Return a mocked feature.""" path = "homeassistant.components.blebox.config_flow.Box" patcher = patch(path, DEFAULT, blebox_uniapi.box.Box, True, True) - yield patcher + return patcher async def test_flow_with_connection_failure(hass, product_class_mock): diff --git a/tests/components/config/test_area_registry.py b/tests/components/config/test_area_registry.py index de3cb78d349..e7b2e47599e 100644 --- a/tests/components/config/test_area_registry.py +++ b/tests/components/config/test_area_registry.py @@ -11,7 +11,7 @@ from tests.common import ANY, mock_area_registry def client(hass, hass_ws_client): """Fixture that can interact with the config manager API.""" hass.loop.run_until_complete(area_registry.async_setup(hass)) - yield hass.loop.run_until_complete(hass_ws_client(hass)) + return hass.loop.run_until_complete(hass_ws_client(hass)) @pytest.fixture diff --git a/tests/components/config/test_device_registry.py b/tests/components/config/test_device_registry.py index 487658ddb27..94493655405 100644 --- a/tests/components/config/test_device_registry.py +++ b/tests/components/config/test_device_registry.py @@ -18,7 +18,7 @@ from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: def client(hass, hass_ws_client): """Fixture that can interact with the config manager API.""" hass.loop.run_until_complete(device_registry.async_setup(hass)) - yield hass.loop.run_until_complete(hass_ws_client(hass)) + return hass.loop.run_until_complete(hass_ws_client(hass)) @pytest.fixture diff --git a/tests/components/config/test_entity_registry.py b/tests/components/config/test_entity_registry.py index 38984d74057..b396f6a6d18 100644 --- a/tests/components/config/test_entity_registry.py +++ b/tests/components/config/test_entity_registry.py @@ -26,7 +26,7 @@ from tests.common import ( def client(hass, hass_ws_client): """Fixture that can interact with the config manager API.""" hass.loop.run_until_complete(entity_registry.async_setup(hass)) - yield hass.loop.run_until_complete(hass_ws_client(hass)) + return hass.loop.run_until_complete(hass_ws_client(hass)) @pytest.fixture diff --git a/tests/components/energy/test_sensor.py b/tests/components/energy/test_sensor.py index 6ea606a4344..0899a5ce84c 100644 --- a/tests/components/energy/test_sensor.py +++ b/tests/components/energy/test_sensor.py @@ -57,7 +57,7 @@ async def setup_integration(recorder_mock): @freeze_time("2022-04-19 07:53:05") def frozen_time(): """Freeze clock for tests.""" - yield + return def get_statistics_for_entity(statistics_results, entity_id): diff --git a/tests/components/generic/conftest.py b/tests/components/generic/conftest.py index 74679f050b6..e9233ffc559 100644 --- a/tests/components/generic/conftest.py +++ b/tests/components/generic/conftest.py @@ -18,7 +18,7 @@ def fakeimgbytes_png(): """Fake image in RAM for testing.""" buf = BytesIO() Image.new("RGB", (1, 1)).save(buf, format="PNG") - yield bytes(buf.getbuffer()) + return bytes(buf.getbuffer()) @pytest.fixture(scope="package") @@ -26,13 +26,13 @@ def fakeimgbytes_jpg(): """Fake image in RAM for testing.""" buf = BytesIO() # fake image in ram for testing. Image.new("RGB", (1, 1)).save(buf, format="jpeg") - yield bytes(buf.getbuffer()) + return bytes(buf.getbuffer()) @pytest.fixture(scope="package") def fakeimgbytes_svg(): """Fake image in RAM for testing.""" - yield bytes( + return bytes( '', encoding="utf-8", ) @@ -43,7 +43,7 @@ def fakeimgbytes_gif(): """Fake image in RAM for testing.""" buf = BytesIO() # fake image in ram for testing. Image.new("RGB", (1, 1)).save(buf, format="gif") - yield bytes(buf.getbuffer()) + return bytes(buf.getbuffer()) @pytest.fixture diff --git a/tests/components/google_assistant_sdk/conftest.py b/tests/components/google_assistant_sdk/conftest.py index 207ceccb342..c994a8b12e3 100644 --- a/tests/components/google_assistant_sdk/conftest.py +++ b/tests/components/google_assistant_sdk/conftest.py @@ -1,6 +1,7 @@ """PyTest fixtures and test helpers.""" -from collections.abc import Awaitable, Callable, Generator +from collections.abc import Awaitable, Callable, Coroutine import time +from typing import Any from google.oauth2.credentials import Credentials import pytest @@ -65,7 +66,7 @@ def mock_config_entry(expires_at: int, scopes: list[str]) -> MockConfigEntry: @pytest.fixture(name="setup_integration") async def mock_setup_integration( hass: HomeAssistant, config_entry: MockConfigEntry -) -> Generator[ComponentSetup, None, None]: +) -> Callable[[], Coroutine[Any, Any, None]]: """Fixture for setting up the component.""" config_entry.add_to_hass(hass) @@ -81,7 +82,7 @@ async def mock_setup_integration( assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - yield func + return func class ExpectedCredentials: diff --git a/tests/components/google_mail/conftest.py b/tests/components/google_mail/conftest.py index e84af4f0ac3..64e37e74b8f 100644 --- a/tests/components/google_mail/conftest.py +++ b/tests/components/google_mail/conftest.py @@ -1,6 +1,7 @@ """Configure tests for the Google Mail integration.""" -from collections.abc import Awaitable, Callable, Generator +from collections.abc import Awaitable, Callable, Coroutine import time +from typing import Any from unittest.mock import patch from httplib2 import Response @@ -93,7 +94,7 @@ def mock_connection(aioclient_mock: AiohttpClientMocker) -> None: @pytest.fixture(name="setup_integration") async def mock_setup_integration( hass: HomeAssistant, config_entry: MockConfigEntry -) -> Generator[ComponentSetup, None, None]: +) -> Callable[[], Coroutine[Any, Any, None]]: """Fixture for setting up the component.""" config_entry.add_to_hass(hass) @@ -116,4 +117,4 @@ async def mock_setup_integration( assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - yield func + return func diff --git a/tests/components/google_sheets/test_init.py b/tests/components/google_sheets/test_init.py index 4c708544099..9d44490d248 100644 --- a/tests/components/google_sheets/test_init.py +++ b/tests/components/google_sheets/test_init.py @@ -1,8 +1,9 @@ """Tests for Google Sheets.""" -from collections.abc import Awaitable, Callable, Generator +from collections.abc import Awaitable, Callable, Coroutine import http import time +from typing import Any from unittest.mock import patch import pytest @@ -58,7 +59,7 @@ def mock_config_entry(expires_at: int, scopes: list[str]) -> MockConfigEntry: @pytest.fixture(name="setup_integration") async def mock_setup_integration( hass: HomeAssistant, config_entry: MockConfigEntry -) -> Generator[ComponentSetup, None, None]: +) -> Callable[[], Coroutine[Any, Any, None]]: """Fixture for setting up the component.""" config_entry.add_to_hass(hass) @@ -74,7 +75,7 @@ async def mock_setup_integration( assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - yield func + return func async def test_setup_success( diff --git a/tests/components/google_travel_time/conftest.py b/tests/components/google_travel_time/conftest.py index ec5a8f16917..cef8dfeb65c 100644 --- a/tests/components/google_travel_time/conftest.py +++ b/tests/components/google_travel_time/conftest.py @@ -21,7 +21,7 @@ async def mock_config_fixture(hass, data, options): config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield config_entry + return config_entry @pytest.fixture(name="bypass_setup") diff --git a/tests/components/google_travel_time/test_sensor.py b/tests/components/google_travel_time/test_sensor.py index d0a94712fcb..c628137d624 100644 --- a/tests/components/google_travel_time/test_sensor.py +++ b/tests/components/google_travel_time/test_sensor.py @@ -69,14 +69,14 @@ def mock_update_duration_fixture(mock_update): } ] } - yield mock_update + return mock_update @pytest.fixture(name="mock_update_empty") def mock_update_empty_fixture(mock_update): """Mock an update to the sensor with an empty response.""" mock_update.return_value = None - yield mock_update + return mock_update @pytest.mark.parametrize( diff --git a/tests/components/history/conftest.py b/tests/components/history/conftest.py index a2916153acc..86d8d2a9421 100644 --- a/tests/components/history/conftest.py +++ b/tests/components/history/conftest.py @@ -27,4 +27,4 @@ def hass_history(hass_recorder): ) assert setup_component(hass, history.DOMAIN, config) - yield hass + return hass diff --git a/tests/components/izone/test_config_flow.py b/tests/components/izone/test_config_flow.py index d48e19181c8..fb231d5da54 100644 --- a/tests/components/izone/test_config_flow.py +++ b/tests/components/izone/test_config_flow.py @@ -14,7 +14,7 @@ def mock_disco(): disco = Mock() disco.pi_disco = Mock() disco.pi_disco.controllers = {} - yield disco + return disco def _mock_start_discovery(hass, mock_disco): diff --git a/tests/components/meraki/test_device_tracker.py b/tests/components/meraki/test_device_tracker.py index e95241cbbc7..a2195b9a7c4 100644 --- a/tests/components/meraki/test_device_tracker.py +++ b/tests/components/meraki/test_device_tracker.py @@ -32,7 +32,7 @@ def meraki_client(event_loop, hass, hass_client): ) ) - yield loop.run_until_complete(hass_client()) + return loop.run_until_complete(hass_client()) async def test_invalid_or_missing_data(mock_device_tracker_conf, meraki_client): diff --git a/tests/components/mjpeg/conftest.py b/tests/components/mjpeg/conftest.py index c09bbde2f1d..0bd85920a8e 100644 --- a/tests/components/mjpeg/conftest.py +++ b/tests/components/mjpeg/conftest.py @@ -59,11 +59,11 @@ def mock_reload_entry() -> Generator[AsyncMock, None, None]: @pytest.fixture -def mock_mjpeg_requests(requests_mock: Mocker) -> Generator[Mocker, None, None]: +def mock_mjpeg_requests(requests_mock: Mocker) -> Mocker: """Fixture to provide a requests mocker.""" requests_mock.get("https://example.com/mjpeg", text="resp") requests_mock.get("https://example.com/still", text="resp") - yield requests_mock + return requests_mock @pytest.fixture diff --git a/tests/components/modbus/conftest.py b/tests/components/modbus/conftest.py index b00f9700f7f..377be04f250 100644 --- a/tests/components/modbus/conftest.py +++ b/tests/components/modbus/conftest.py @@ -179,4 +179,4 @@ async def mock_ha_fixture(hass, mock_pymodbus_return): @pytest.fixture(name="caplog_setup_text") async def caplog_setup_text_fixture(caplog): """Return setup log of integration.""" - yield caplog.text + return caplog.text diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index 2a212535916..8603b3e278b 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -115,7 +115,7 @@ async def mock_modbus_with_pymodbus_fixture(hass, caplog, do_config, mock_pymodb await hass.async_block_till_done() assert DOMAIN in hass.config.components assert caplog.text == "" - yield mock_pymodbus + return mock_pymodbus async def test_number_validator(): @@ -582,7 +582,7 @@ async def mock_modbus_read_pymodbus_fixture( freezer.tick(timedelta(seconds=DEFAULT_SCAN_INTERVAL + 60)) async_fire_time_changed(hass) await hass.async_block_till_done() - yield mock_pymodbus + return mock_pymodbus @pytest.mark.parametrize( diff --git a/tests/components/nextbus/test_sensor.py b/tests/components/nextbus/test_sensor.py index f113d5c83da..7ac514006b1 100644 --- a/tests/components/nextbus/test_sensor.py +++ b/tests/components/nextbus/test_sensor.py @@ -69,7 +69,7 @@ def mock_nextbus_predictions(mock_nextbus): instance = mock_nextbus.return_value instance.get_predictions_for_multi_stops.return_value = BASIC_RESULTS - yield instance.get_predictions_for_multi_stops + return instance.get_predictions_for_multi_stops @pytest.fixture diff --git a/tests/components/nibe_heatpump/conftest.py b/tests/components/nibe_heatpump/conftest.py index 43647a73f48..0ae9c73e6b8 100644 --- a/tests/components/nibe_heatpump/conftest.py +++ b/tests/components/nibe_heatpump/conftest.py @@ -54,4 +54,4 @@ async def fixture_coils(mock_connection): mock_connection.read_coil = read_coil mock_connection.read_coils = read_coils - yield coils + return coils diff --git a/tests/components/notion/conftest.py b/tests/components/notion/conftest.py index 3250beffcf5..a66d99d41ce 100644 --- a/tests/components/notion/conftest.py +++ b/tests/components/notion/conftest.py @@ -82,4 +82,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aionotion): """Define a fixture to set up notion.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield diff --git a/tests/components/openuv/conftest.py b/tests/components/openuv/conftest.py index 564323d6894..7d9e8b9a4fd 100644 --- a/tests/components/openuv/conftest.py +++ b/tests/components/openuv/conftest.py @@ -79,4 +79,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_pyopenuv): """Define a fixture to set up openuv.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield diff --git a/tests/components/owntracks/test_device_tracker.py b/tests/components/owntracks/test_device_tracker.py index ef36d4a9e28..3374eb1d3e4 100644 --- a/tests/components/owntracks/test_device_tracker.py +++ b/tests/components/owntracks/test_device_tracker.py @@ -290,7 +290,6 @@ def setup_comp(hass, mock_device_tracker_conf, mqtt_mock): hass.states.async_set("zone.inner_2", "zoning", INNER_ZONE) hass.states.async_set("zone.outer", "zoning", OUTER_ZONE) - yield async def setup_owntracks(hass, config, ctx_cls=owntracks.OwnTracksContext): @@ -334,7 +333,7 @@ def context(hass, setup_comp): """Get the current context.""" return context - yield get_context + return get_context async def send_message(hass, topic, message, corrupt=False): diff --git a/tests/components/purpleair/conftest.py b/tests/components/purpleair/conftest.py index e5d6376a208..85598815c2c 100644 --- a/tests/components/purpleair/conftest.py +++ b/tests/components/purpleair/conftest.py @@ -83,4 +83,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aiopurpleair): """Define a fixture to set up purpleair.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield diff --git a/tests/components/recollect_waste/conftest.py b/tests/components/recollect_waste/conftest.py index 39bcb7f4e07..861d4804f85 100644 --- a/tests/components/recollect_waste/conftest.py +++ b/tests/components/recollect_waste/conftest.py @@ -70,4 +70,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aiorecollect): """Define a fixture to set up recollect_waste.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield diff --git a/tests/components/rfxtrx/conftest.py b/tests/components/rfxtrx/conftest.py index 86fec2fdc7f..c5ab8f71011 100644 --- a/tests/components/rfxtrx/conftest.py +++ b/tests/components/rfxtrx/conftest.py @@ -73,7 +73,7 @@ async def rfxtrx_fixture(hass): async def rfxtrx_automatic_fixture(hass, rfxtrx): """Fixture that starts up with automatic additions.""" await setup_rfx_test_cfg(hass, automatic_add=True, devices={}) - yield rfxtrx + return rfxtrx @pytest.fixture diff --git a/tests/components/ridwell/conftest.py b/tests/components/ridwell/conftest.py index 31788bc5282..e86243da533 100644 --- a/tests/components/ridwell/conftest.py +++ b/tests/components/ridwell/conftest.py @@ -86,4 +86,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_aioridwell): """Define a fixture to set up ridwell.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield diff --git a/tests/components/scene/test_init.py b/tests/components/scene/test_init.py index 3dd0cfce7b9..bee2dfcd404 100644 --- a/tests/components/scene/test_init.py +++ b/tests/components/scene/test_init.py @@ -25,7 +25,7 @@ def entities(hass): """Initialize the test light.""" platform = getattr(hass.components, "test.light") platform.init() - yield platform.ENTITIES[0:2] + return platform.ENTITIES[0:2] async def test_config_yaml_alias_anchor(hass, entities, enable_custom_integrations): diff --git a/tests/components/smtp/test_notify.py b/tests/components/smtp/test_notify.py index ac742e10ea1..bad63924006 100644 --- a/tests/components/smtp/test_notify.py +++ b/tests/components/smtp/test_notify.py @@ -78,7 +78,7 @@ def message(): 0, True, ) - yield mailer + return mailer HTML = """ diff --git a/tests/components/snooz/conftest.py b/tests/components/snooz/conftest.py index cba64633c8d..cb4873e7937 100644 --- a/tests/components/snooz/conftest.py +++ b/tests/components/snooz/conftest.py @@ -20,4 +20,4 @@ async def mock_connected_snooz(hass: HomeAssistant): device = await create_mock_snooz() entry = await create_mock_snooz_config_entry(hass, device) - yield SnoozFixture(entry, device) + return SnoozFixture(entry, device) diff --git a/tests/components/snooz/test_fan.py b/tests/components/snooz/test_fan.py index 19c794d6f04..d4f82ce5724 100644 --- a/tests/components/snooz/test_fan.py +++ b/tests/components/snooz/test_fan.py @@ -286,7 +286,7 @@ async def fixture_snooz_fan_entity_id( ) -> str: """Mock a Snooz fan entity and config entry.""" - yield get_fan_entity_id(hass, mock_connected_snooz.device) + return get_fan_entity_id(hass, mock_connected_snooz.device) def get_fan_entity_id(hass: HomeAssistant, device: MockSnoozDevice) -> str: diff --git a/tests/components/soundtouch/conftest.py b/tests/components/soundtouch/conftest.py index dc5621ed507..1cdd37add4b 100644 --- a/tests/components/soundtouch/conftest.py +++ b/tests/components/soundtouch/conftest.py @@ -23,7 +23,7 @@ DEVICE_2_ENTITY_ID = f"{MEDIA_PLAYER_DOMAIN}.my_soundtouch_2" @pytest.fixture def device1_config() -> MockConfigEntry: """Mock SoundTouch device 1 config entry.""" - yield MockConfigEntry( + return MockConfigEntry( domain=DOMAIN, unique_id=DEVICE_1_ID, data={ @@ -36,7 +36,7 @@ def device1_config() -> MockConfigEntry: @pytest.fixture def device2_config() -> MockConfigEntry: """Mock SoundTouch device 2 config entry.""" - yield MockConfigEntry( + return MockConfigEntry( domain=DOMAIN, unique_id=DEVICE_2_ID, data={ @@ -155,7 +155,7 @@ def device1_requests_mock( requests_mock.get(f"{DEVICE_1_URL}/volume", text=device1_volume) requests_mock.get(f"{DEVICE_1_URL}/presets", text=device1_presets) requests_mock.get(f"{DEVICE_1_URL}/getZone", text=device1_zone_master) - yield requests_mock + return requests_mock @pytest.fixture @@ -229,7 +229,7 @@ def device1_requests_mock_key( device1_requests_mock: Mocker, ): """Mock SoundTouch device 1 API - key endpoint.""" - yield device1_requests_mock.post(f"{DEVICE_1_URL}/key") + return device1_requests_mock.post(f"{DEVICE_1_URL}/key") @pytest.fixture @@ -237,7 +237,7 @@ def device1_requests_mock_volume( device1_requests_mock: Mocker, ): """Mock SoundTouch device 1 API - volume endpoint.""" - yield device1_requests_mock.post(f"{DEVICE_1_URL}/volume") + return device1_requests_mock.post(f"{DEVICE_1_URL}/volume") @pytest.fixture @@ -245,7 +245,7 @@ def device1_requests_mock_select( device1_requests_mock: Mocker, ): """Mock SoundTouch device 1 API - select endpoint.""" - yield device1_requests_mock.post(f"{DEVICE_1_URL}/select") + return device1_requests_mock.post(f"{DEVICE_1_URL}/select") @pytest.fixture @@ -253,7 +253,7 @@ def device1_requests_mock_set_zone( device1_requests_mock: Mocker, ): """Mock SoundTouch device 1 API - setZone endpoint.""" - yield device1_requests_mock.post(f"{DEVICE_1_URL}/setZone") + return device1_requests_mock.post(f"{DEVICE_1_URL}/setZone") @pytest.fixture @@ -261,7 +261,7 @@ def device1_requests_mock_add_zone_slave( device1_requests_mock: Mocker, ): """Mock SoundTouch device 1 API - addZoneSlave endpoint.""" - yield device1_requests_mock.post(f"{DEVICE_1_URL}/addZoneSlave") + return device1_requests_mock.post(f"{DEVICE_1_URL}/addZoneSlave") @pytest.fixture @@ -269,7 +269,7 @@ def device1_requests_mock_remove_zone_slave( device1_requests_mock: Mocker, ): """Mock SoundTouch device 1 API - removeZoneSlave endpoint.""" - yield device1_requests_mock.post(f"{DEVICE_1_URL}/removeZoneSlave") + return device1_requests_mock.post(f"{DEVICE_1_URL}/removeZoneSlave") @pytest.fixture @@ -277,7 +277,7 @@ def device1_requests_mock_dlna( device1_requests_mock: Mocker, ): """Mock SoundTouch device 1 API - DLNA endpoint.""" - yield device1_requests_mock.post(f"http://{DEVICE_1_IP}:8091/AVTransport/Control") + return device1_requests_mock.post(f"http://{DEVICE_1_IP}:8091/AVTransport/Control") @pytest.fixture @@ -294,4 +294,4 @@ def device2_requests_mock_standby( requests_mock.get(f"{DEVICE_2_URL}/now_playing", text=device2_now_playing_standby) requests_mock.get(f"{DEVICE_2_URL}/getZone", text=device2_zone_slave) - yield requests_mock + return requests_mock diff --git a/tests/components/switch/test_init.py b/tests/components/switch/test_init.py index 29f77b0d470..8e24bc4b3ee 100644 --- a/tests/components/switch/test_init.py +++ b/tests/components/switch/test_init.py @@ -14,7 +14,7 @@ def entities(hass): """Initialize the test switch.""" platform = getattr(hass.components, "test.switch") platform.init() - yield platform.ENTITIES + return platform.ENTITIES async def test_methods(hass, entities, enable_custom_integrations): diff --git a/tests/components/synology_dsm/conftest.py b/tests/components/synology_dsm/conftest.py index 315ae7a5c2a..74eb48f5b36 100644 --- a/tests/components/synology_dsm/conftest.py +++ b/tests/components/synology_dsm/conftest.py @@ -34,4 +34,4 @@ def fixture_dsm(): dsm.surveillance_station.update = AsyncMock(return_value=True) dsm.upgrade.update = AsyncMock(return_value=True) - yield dsm + return dsm diff --git a/tests/components/template/conftest.py b/tests/components/template/conftest.py index 5ccc9e6479a..207a7c87886 100644 --- a/tests/components/template/conftest.py +++ b/tests/components/template/conftest.py @@ -30,4 +30,4 @@ async def start_ha(hass, count, domain, config, caplog): @pytest.fixture async def caplog_setup_text(caplog): """Return setup log of integration.""" - yield caplog.text + return caplog.text diff --git a/tests/components/tile/conftest.py b/tests/components/tile/conftest.py index 187d8f3a2c1..577abd6fa70 100644 --- a/tests/components/tile/conftest.py +++ b/tests/components/tile/conftest.py @@ -64,4 +64,3 @@ async def setup_config_entry_fixture(hass, config_entry, mock_pytile): """Define a fixture to set up tile.""" assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - yield diff --git a/tests/components/upnp/conftest.py b/tests/components/upnp/conftest.py index f26fb39e42a..4c125a9d6e9 100644 --- a/tests/components/upnp/conftest.py +++ b/tests/components/upnp/conftest.py @@ -206,4 +206,4 @@ async def mock_config_entry( await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - yield entry + return entry diff --git a/tests/components/vultr/conftest.py b/tests/components/vultr/conftest.py index 76c48c2574b..0d69cf53335 100644 --- a/tests/components/vultr/conftest.py +++ b/tests/components/vultr/conftest.py @@ -26,5 +26,3 @@ def valid_config(hass: HomeAssistant, requests_mock): ): # Setup hub vultr.setup(hass, VALID_CONFIG) - - yield diff --git a/tests/components/vultr/test_switch.py b/tests/components/vultr/test_switch.py index 8997d1c0b9d..5dbfce800c5 100644 --- a/tests/components/vultr/test_switch.py +++ b/tests/components/vultr/test_switch.py @@ -45,7 +45,7 @@ def load_hass_devices(hass: HomeAssistant): for config in CONFIGS: vultr.setup_platform(hass, config, add_entities, None) - yield hass_devices + return hass_devices @pytest.mark.usefixtures("valid_config") diff --git a/tests/components/waze_travel_time/test_sensor.py b/tests/components/waze_travel_time/test_sensor.py index 569335f9e6c..578ab0add8d 100644 --- a/tests/components/waze_travel_time/test_sensor.py +++ b/tests/components/waze_travel_time/test_sensor.py @@ -39,7 +39,6 @@ def mock_update_wrcerror_fixture(mock_wrc): """Mock an update to the sensor failed with WRCError.""" obj = mock_wrc.return_value obj.calc_all_routes_info.side_effect = WRCError("test") - yield @pytest.fixture(name="mock_update_keyerror") @@ -47,7 +46,6 @@ def mock_update_keyerror_fixture(mock_wrc): """Mock an update to the sensor failed with KeyError.""" obj = mock_wrc.return_value obj.calc_all_routes_info.side_effect = KeyError("test") - yield @pytest.mark.parametrize( diff --git a/tests/components/wemo/test_wemo_device.py b/tests/components/wemo/test_wemo_device.py index a16efb173ae..6bacb7690bd 100644 --- a/tests/components/wemo/test_wemo_device.py +++ b/tests/components/wemo/test_wemo_device.py @@ -197,7 +197,7 @@ class TestInsight: "ontotal": 0, "powerthreshold": 0, } - yield pywemo_device + return pywemo_device @pytest.mark.parametrize( "subscribed,state,expected_calls", diff --git a/tests/components/whirlpool/conftest.py b/tests/components/whirlpool/conftest.py index dd06c2d768f..71530e3337f 100644 --- a/tests/components/whirlpool/conftest.py +++ b/tests/components/whirlpool/conftest.py @@ -88,13 +88,13 @@ def get_aircon_mock(said): @pytest.fixture(name="mock_aircon1_api", autouse=False) def fixture_mock_aircon1_api(mock_auth_api, mock_appliances_manager_api): """Set up air conditioner API fixture.""" - yield get_aircon_mock(MOCK_SAID1) + return get_aircon_mock(MOCK_SAID1) @pytest.fixture(name="mock_aircon2_api", autouse=False) def fixture_mock_aircon2_api(mock_auth_api, mock_appliances_manager_api): """Set up air conditioner API fixture.""" - yield get_aircon_mock(MOCK_SAID2) + return get_aircon_mock(MOCK_SAID2) @pytest.fixture(name="mock_aircon_api_instances", autouse=False) @@ -143,13 +143,13 @@ def get_sensor_mock(said): @pytest.fixture(name="mock_sensor1_api", autouse=False) def fixture_mock_sensor1_api(mock_auth_api, mock_appliances_manager_api): """Set up sensor API fixture.""" - yield get_sensor_mock(MOCK_SAID3) + return get_sensor_mock(MOCK_SAID3) @pytest.fixture(name="mock_sensor2_api", autouse=False) def fixture_mock_sensor2_api(mock_auth_api, mock_appliances_manager_api): """Set up sensor API fixture.""" - yield get_sensor_mock(MOCK_SAID4) + return get_sensor_mock(MOCK_SAID4) @pytest.fixture(name="mock_sensor_api_instances", autouse=False) diff --git a/tests/conftest.py b/tests/conftest.py index ede6abab54f..b7544793f50 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -205,7 +205,7 @@ util.get_local_ip = lambda: "127.0.0.1" def caplog_fixture(caplog): """Set log level to debug for tests using the caplog fixture.""" caplog.set_level(logging.DEBUG) - yield caplog + return caplog @pytest.fixture(autouse=True, scope="module") @@ -1103,7 +1103,7 @@ async def async_setup_recorder_instance( @pytest.fixture async def recorder_mock(recorder_config, async_setup_recorder_instance, hass): """Fixture with in-memory recorder.""" - yield await async_setup_recorder_instance(hass, recorder_config) + return await async_setup_recorder_instance(hass, recorder_config) @pytest.fixture diff --git a/tests/hassfest/test_requirements.py b/tests/hassfest/test_requirements.py index fc366db74fa..cb73e5b9603 100644 --- a/tests/hassfest/test_requirements.py +++ b/tests/hassfest/test_requirements.py @@ -20,7 +20,7 @@ def integration(): "requirements": [], }, ) - yield integration + return integration def test_validate_requirements_format_with_space(integration: Integration): diff --git a/tests/helpers/test_aiohttp_client.py b/tests/helpers/test_aiohttp_client.py index e3ea2af9d14..5af3fd89703 100644 --- a/tests/helpers/test_aiohttp_client.py +++ b/tests/helpers/test_aiohttp_client.py @@ -45,7 +45,7 @@ def camera_client_fixture(hass, hass_client): ) hass.loop.run_until_complete(hass.async_block_till_done()) - yield hass.loop.run_until_complete(hass_client()) + return hass.loop.run_until_complete(hass_client()) async def test_get_clientsession_with_ssl(hass): diff --git a/tests/ruff.toml b/tests/ruff.toml index 767e0a30a61..18a3ca5626f 100644 --- a/tests/ruff.toml +++ b/tests/ruff.toml @@ -5,4 +5,5 @@ extend-select = [ "PT001", # Use @pytest.fixture without parentheses "PT013", # Found incorrect pytest import, use simple import pytest instead "PT015", # Assertion always fails, replace with pytest.fail() + "PT022", # No teardown in fixture, replace useless yield with return ] \ No newline at end of file