From caa25bf1b26d5c4247512191ef10b495dd88becd Mon Sep 17 00:00:00 2001 From: Jake Martin Date: Fri, 11 Sep 2026 15:32:05 +0100 Subject: [PATCH] Ignore core authorization errors in translation checks (#180817) Co-authored-by: Markus Tuominen <3738613+Markus98@users.noreply.github.com> --- tests/components/conftest.py | 4 ++- tests/components/test_conftest.py | 44 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/components/test_conftest.py diff --git a/tests/components/conftest.py b/tests/components/conftest.py index 971743f48094..19e64adb53d1 100644 --- a/tests/components/conftest.py +++ b/tests/components/conftest.py @@ -82,7 +82,7 @@ from homeassistant.data_entry_flow import ( FlowResultType, section, ) -from homeassistant.exceptions import HomeAssistantError +from homeassistant.exceptions import HomeAssistantError, Unauthorized from homeassistant.helpers import issue_registry as ir from homeassistant.helpers.translation import async_get_translations from homeassistant.helpers.typing import VolSchemaType @@ -1249,6 +1249,8 @@ async def _check_exception_translation( request: pytest.FixtureRequest, ignore_translations_for_mock_domains: set[str], ) -> None: + if isinstance(exception, Unauthorized): + return if exception.translation_key is None: if ( _get_request_quality_scale(request, "exception-translations") diff --git a/tests/components/test_conftest.py b/tests/components/test_conftest.py new file mode 100644 index 000000000000..dc91886328b6 --- /dev/null +++ b/tests/components/test_conftest.py @@ -0,0 +1,44 @@ +"""Tests for component test fixtures.""" + +from collections.abc import Callable + +import pytest + +from homeassistant.core import HomeAssistant +from homeassistant.exceptions import Unauthorized, UnknownUser + +from . import conftest as components_conftest + +from tests.common import QualityScaleStatus + + +@pytest.mark.parametrize( + "exception_type", + [ + pytest.param(Unauthorized, id="unauthorized"), + pytest.param(UnknownUser, id="unknown-user"), + ], +) +async def test_authorization_errors_do_not_require_integration_translations( + hass: HomeAssistant, + monkeypatch: pytest.MonkeyPatch, + request: pytest.FixtureRequest, + exception_type: Callable[[], Unauthorized], +) -> None: + """Test core authorization errors do not require integration translations.""" + monkeypatch.setattr( + components_conftest, + "_get_request_quality_scale", + lambda *_: QualityScaleStatus.DONE, + ) + translation_errors: dict[str, str] = {} + + await components_conftest._check_exception_translation( + hass, + exception_type(), + translation_errors, + request, + set(), + ) + + assert not translation_errors