diff --git a/tests/conftest.py b/tests/conftest.py index c04b90d349ed30..09ad70bfcf1b42 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -376,6 +376,13 @@ def verify_cleanup( ) +@pytest.fixture(autouse=True) +def reset_hass_threading_local_object() -> Generator[None, None, None]: + """Reset the _Hass threading.local object for every test case.""" + yield + ha._hass.__dict__.clear() + + @pytest.fixture(autouse=True) def bcrypt_cost() -> Generator[None, None, None]: """Run with reduced rounds during tests, to speed up uses.""" @@ -559,9 +566,6 @@ def exc_handle(loop, context): # Restore timezone, it is set when creating the hass object dt_util.DEFAULT_TIME_ZONE = orig_tz - # Reset the _Hass threading.local object - ha._hass.__dict__.clear() - for ex in exceptions: if ( request.module.__name__,