From 74387cc3e049783a2b646273b3731c36d166a1a5 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:28:39 +0200 Subject: [PATCH 1/2] Reset the threading.local _hass object every time --- tests/conftest.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index c04b90d349ed30..c4923309167ae0 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.""" From 1e74deb451510251bb8008c078c73a48eea413d9 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:58:28 +0200 Subject: [PATCH 2/2] Remove reset from hass fixture --- tests/conftest.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c4923309167ae0..09ad70bfcf1b42 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -566,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__,