Only load translations for an integration once per test session (#117118)
This commit is contained in:
parent
9e107a02db
commit
d7aa24fa50
4 changed files with 55 additions and 9 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue