diff --git a/tests/components/application_credentials/test_init.py b/tests/components/application_credentials/test_init.py index 686cf378fd456a..b72d9653c2d040 100644 --- a/tests/components/application_credentials/test_init.py +++ b/tests/components/application_credentials/test_init.py @@ -48,18 +48,6 @@ TEST_DOMAIN = "fake_integration" -@pytest.fixture -def ignore_translations() -> list[str]: - """Ignore specific translations. - - We can ignore translations for the fake_integration we are testing with. - """ - return [ - f"component.{TEST_DOMAIN}.config.abort.missing_configuration", - f"component.{TEST_DOMAIN}.config.abort.missing_credentials", - ] - - @pytest.fixture async def authorization_server() -> AuthorizationServer: """Fixture AuthorizationServer for mock application_credentials integration.""" @@ -435,6 +423,10 @@ async def test_import_named_credential( ] +@pytest.mark.parametrize( + "ignore_translations", + ["component.fake_integration.config.abort.missing_credentials"], +) async def test_config_flow_no_credentials(hass: HomeAssistant) -> None: """Test config flow base case with no credentials registered.""" result = await hass.config_entries.flow.async_init( @@ -444,6 +436,10 @@ async def test_config_flow_no_credentials(hass: HomeAssistant) -> None: assert result.get("reason") == "missing_credentials" +@pytest.mark.parametrize( + "ignore_translations", + ["component.fake_integration.config.abort.missing_credentials"], +) async def test_config_flow_other_domain( hass: HomeAssistant, ws_client: ClientFixture, @@ -571,6 +567,10 @@ async def test_config_flow_multiple_entries( ) +@pytest.mark.parametrize( + "ignore_translations", + ["component.fake_integration.config.abort.missing_credentials"], +) async def test_config_flow_create_delete_credential( hass: HomeAssistant, ws_client: ClientFixture, @@ -616,6 +616,10 @@ async def test_config_flow_with_config_credential( assert result["data"].get("auth_implementation") == TEST_DOMAIN +@pytest.mark.parametrize( + "ignore_translations", + ["component.fake_integration.config.abort.missing_configuration"], +) @pytest.mark.parametrize("mock_application_credentials_integration", [None]) async def test_import_without_setup(hass: HomeAssistant, config_credential) -> None: """Test import of credentials without setting up the integration.""" @@ -631,6 +635,10 @@ async def test_import_without_setup(hass: HomeAssistant, config_credential) -> N assert result.get("reason") == "missing_configuration" +@pytest.mark.parametrize( + "ignore_translations", + ["component.fake_integration.config.abort.missing_configuration"], +) @pytest.mark.parametrize("mock_application_credentials_integration", [None]) async def test_websocket_without_platform( hass: HomeAssistant, ws_client: ClientFixture diff --git a/tests/components/conftest.py b/tests/components/conftest.py index 79f4d8b1a6994b..dcd537f9b320bf 100644 --- a/tests/components/conftest.py +++ b/tests/components/conftest.py @@ -468,7 +468,7 @@ def supervisor_client() -> Generator[AsyncMock]: async def _ensure_translation_exists( hass: HomeAssistant, - ignore_translations: list[str], + ignore_translations: dict[str, StoreInfo], category: str, component: str, key: str, @@ -476,6 +476,7 @@ async def _ensure_translation_exists( """Raise if translation doesn't exist.""" full_key = f"component.{component}.{category}.{key}" if full_key in ignore_translations: + ignore_translations[full_key] = "used" return translations = await async_get_translations(hass, "en", category, [component]) @@ -497,14 +498,14 @@ async def _ensure_translation_exists( ): return - raise ValueError( + pytest.fail( f"Translation not found for {component}: `{category}.{key}`. " f"Please add to homeassistant/components/{component}/strings.json" ) @pytest.fixture -def ignore_translations() -> list[str]: +def ignore_translations() -> str | list[str]: """Ignore specific translations. Override or parametrize this fixture with a fixture that returns, @@ -514,8 +515,12 @@ def ignore_translations() -> list[str]: @pytest.fixture(autouse=True) -def check_config_translations(ignore_translations: list[str]) -> Generator[None]: +def check_config_translations(ignore_translations: str | list[str]) -> Generator[None]: """Ensure config_flow translations are available.""" + if not isinstance(ignore_translations, list): + ignore_translations = [ignore_translations] + + _ignore_translations = {k: "unused" for k in ignore_translations} _original = FlowManager._async_handle_step async def _async_handle_step( @@ -535,7 +540,7 @@ async def _async_handle_step( ): await _ensure_translation_exists( flow.hass, - ignore_translations, + _ignore_translations, category, component, f"abort.{result["reason"]}", @@ -548,3 +553,10 @@ async def _async_handle_step( _async_handle_step, ): yield + + unused_ignore = [k for k, v in _ignore_translations.items() if v == "unused"] + if unused_ignore: + pytest.fail( + f"Unused ignore translations: {', '.join(unused_ignore)}. " + "Please remove them from the ignore_translations fixture." + ) diff --git a/tests/components/matter/test_config_flow.py b/tests/components/matter/test_config_flow.py index da773a360b8c28..de964d482851ec 100644 --- a/tests/components/matter/test_config_flow.py +++ b/tests/components/matter/test_config_flow.py @@ -827,10 +827,6 @@ async def test_addon_running( assert setup_entry.call_count == 1 -@pytest.mark.parametrize( # Remove when translations fixed - "ignore_translations", - ["component.matter.config.abort.cannot_connect"], -) @pytest.mark.parametrize( ( "discovery_info", diff --git a/tests/components/melcloud/test_config_flow.py b/tests/components/melcloud/test_config_flow.py index b575d5073dcbae..baaa7861c7b597 100644 --- a/tests/components/melcloud/test_config_flow.py +++ b/tests/components/melcloud/test_config_flow.py @@ -98,15 +98,6 @@ async def test_form_errors( assert result["reason"] == reason -@pytest.mark.parametrize( # Remove when translations fixed - "ignore_translations", - [ - [ - "component.melcloud.config.abort.cannot_connect", - "component.melcloud.config.abort.invalid_auth", - ], - ], -) @pytest.mark.parametrize( ("error", "message"), [ diff --git a/tests/components/tplink/test_config_flow.py b/tests/components/tplink/test_config_flow.py index e8778b59225b80..40bd4383513ebc 100644 --- a/tests/components/tplink/test_config_flow.py +++ b/tests/components/tplink/test_config_flow.py @@ -1348,10 +1348,6 @@ async def test_reauth_errors( assert result3["reason"] == "reauth_successful" -@pytest.mark.parametrize( # Remove when translations fixed - "ignore_translations", - ["component.tplink.config.abort.cannot_connect"], -) @pytest.mark.parametrize( ("error_type", "expected_flow"), [