Only load translations for an integration once per test session (#117118)

This commit is contained in:
J. Nick Koston 2024-05-11 12:00:02 +09:00 committed by GitHub
parent 9e107a02db
commit d7aa24fa50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 9 deletions

View file

@ -1165,6 +1165,31 @@ def mock_get_source_ip() -> Generator[patch, None, None]:
patcher.stop()
@pytest.fixture(autouse=True, scope="session")
def translations_once() -> Generator[patch, None, None]:
"""Only load translations once per session."""
from homeassistant.helpers.translation import _TranslationsCacheData
cache = _TranslationsCacheData({}, {})
patcher = patch(
"homeassistant.helpers.translation._TranslationsCacheData",
return_value=cache,
)
patcher.start()
try:
yield patcher
finally:
patcher.stop()
@pytest.fixture
def disable_translations_once(translations_once):
"""Override loading translations once."""
translations_once.stop()
yield
translations_once.start()
@pytest.fixture
def mock_zeroconf() -> Generator[None, None, None]:
"""Mock zeroconf."""