Convert test helpers to get hass instance to contextmanagers (#109990)

* Convert get_test_home_assistant helper to contextmanager

* Convert async_test_home_assistant helper to contextmanager

* Move timezone reset to async_test_home_assistant helper
This commit is contained in:
Marc Mueller 2024-02-11 21:23:51 +01:00 committed by GitHub
parent 3342e6ddbd
commit 2ef2172b01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 750 additions and 784 deletions

View file

@ -119,14 +119,19 @@ class TestComponentsCore(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self._manager = get_test_home_assistant()
self.hass = self._manager.__enter__()
assert asyncio.run_coroutine_threadsafe(
async_setup_component(self.hass, "homeassistant", {}), self.hass.loop
).result()
self.hass.states.set("light.Bowl", STATE_ON)
self.hass.states.set("light.Ceiling", STATE_OFF)
self.addCleanup(self.hass.stop)
def tearDown(self) -> None:
"""Tear down hass object."""
self.hass.stop()
self._manager.__exit__(None, None, None)
def test_is_on(self):
"""Test is_on method."""