From f120f55d860818c81c4d9f562ebd72f3cec96db3 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:20:11 +0200 Subject: [PATCH] Move enable_bluetooth fixture to decorator (#118803) --- tests/components/esphome/test_diagnostics.py | 3 ++- tests/components/ibeacon/test_config_flow.py | 13 ++++++----- .../private_ble_device/test_config_flow.py | 22 ++++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tests/components/esphome/test_diagnostics.py b/tests/components/esphome/test_diagnostics.py index 1cf4f77875f..4fb8f993aca 100644 --- a/tests/components/esphome/test_diagnostics.py +++ b/tests/components/esphome/test_diagnostics.py @@ -2,6 +2,7 @@ from unittest.mock import ANY +import pytest from syrupy import SnapshotAssertion from homeassistant.components import bluetooth @@ -14,11 +15,11 @@ from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.typing import ClientSessionGenerator +@pytest.mark.usefixtures("enable_bluetooth") async def test_diagnostics( hass: HomeAssistant, hass_client: ClientSessionGenerator, init_integration: MockConfigEntry, - enable_bluetooth: None, mock_dashboard, snapshot: SnapshotAssertion, ) -> None: diff --git a/tests/components/ibeacon/test_config_flow.py b/tests/components/ibeacon/test_config_flow.py index 0833508d03f..3b5aadfaeab 100644 --- a/tests/components/ibeacon/test_config_flow.py +++ b/tests/components/ibeacon/test_config_flow.py @@ -2,6 +2,8 @@ from unittest.mock import patch +import pytest + from homeassistant import config_entries from homeassistant.components.ibeacon.const import CONF_ALLOW_NAMELESS_UUIDS, DOMAIN from homeassistant.core import HomeAssistant @@ -22,7 +24,8 @@ async def test_setup_user_no_bluetooth( assert result["reason"] == "bluetooth_not_available" -async def test_setup_user(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_setup_user(hass: HomeAssistant) -> None: """Test setting up via user interaction with bluetooth enabled.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -39,9 +42,8 @@ async def test_setup_user(hass: HomeAssistant, enable_bluetooth: None) -> None: assert result2["data"] == {} -async def test_setup_user_already_setup( - hass: HomeAssistant, enable_bluetooth: None -) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_setup_user_already_setup(hass: HomeAssistant) -> None: """Test setting up via user when already setup .""" MockConfigEntry(domain=DOMAIN).add_to_hass(hass) result = await hass.config_entries.flow.async_init( @@ -52,7 +54,8 @@ async def test_setup_user_already_setup( assert result["reason"] == "single_instance_allowed" -async def test_options_flow(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_options_flow(hass: HomeAssistant) -> None: """Test config flow options.""" config_entry = MockConfigEntry(domain=DOMAIN) config_entry.add_to_hass(hass) diff --git a/tests/components/private_ble_device/test_config_flow.py b/tests/components/private_ble_device/test_config_flow.py index a8821dddace..7c9b4807621 100644 --- a/tests/components/private_ble_device/test_config_flow.py +++ b/tests/components/private_ble_device/test_config_flow.py @@ -2,6 +2,8 @@ from unittest.mock import patch +import pytest + from homeassistant import config_entries from homeassistant.components.private_ble_device import const from homeassistant.core import HomeAssistant @@ -30,7 +32,8 @@ async def test_setup_user_no_bluetooth( assert result["reason"] == "bluetooth_not_available" -async def test_invalid_irk(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_invalid_irk(hass: HomeAssistant) -> None: """Test invalid irk.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -43,7 +46,8 @@ async def test_invalid_irk(hass: HomeAssistant, enable_bluetooth: None) -> None: assert_form_error(result, "irk", "irk_not_valid") -async def test_invalid_irk_base64(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_invalid_irk_base64(hass: HomeAssistant) -> None: """Test invalid irk.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -56,7 +60,8 @@ async def test_invalid_irk_base64(hass: HomeAssistant, enable_bluetooth: None) - assert_form_error(result, "irk", "irk_not_valid") -async def test_invalid_irk_hex(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_invalid_irk_hex(hass: HomeAssistant) -> None: """Test invalid irk.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -69,7 +74,8 @@ async def test_invalid_irk_hex(hass: HomeAssistant, enable_bluetooth: None) -> N assert_form_error(result, "irk", "irk_not_valid") -async def test_irk_not_found(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_irk_not_found(hass: HomeAssistant) -> None: """Test irk not found.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -83,7 +89,8 @@ async def test_irk_not_found(hass: HomeAssistant, enable_bluetooth: None) -> Non assert_form_error(result, "irk", "irk_not_found") -async def test_flow_works(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_flow_works(hass: HomeAssistant) -> None: """Test config flow works.""" inject_bluetooth_service_info( @@ -120,9 +127,8 @@ async def test_flow_works(hass: HomeAssistant, enable_bluetooth: None) -> None: assert result["result"].unique_id == "00000000000000000000000000000000" -async def test_flow_works_by_base64( - hass: HomeAssistant, enable_bluetooth: None -) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_flow_works_by_base64(hass: HomeAssistant) -> None: """Test config flow works.""" inject_bluetooth_service_info(