From 2fd872b253c112765fd1ac367ffa35871b05d79e Mon Sep 17 00:00:00 2001
From: "J. Nick Koston" <nick@koston.org>
Date: Mon, 27 Mar 2023 23:02:08 -1000
Subject: [PATCH] Speed up profiler lru test (#90395)

---
 tests/components/profiler/test_init.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tests/components/profiler/test_init.py b/tests/components/profiler/test_init.py
index 2c283463b62..af642c779e1 100644
--- a/tests/components/profiler/test_init.py
+++ b/tests/components/profiler/test_init.py
@@ -10,6 +10,7 @@ import py
 import pytest
 
 from homeassistant.components.profiler import (
+    _LRU_CACHE_WRAPPER_OBJECT,
     CONF_SECONDS,
     SERVICE_DUMP_LOG_OBJECTS,
     SERVICE_LOG_EVENT_LOOP_SCHEDULED,
@@ -253,10 +254,15 @@ async def test_lru_stats(hass: HomeAssistant, caplog: pytest.LogCaptureFixture)
     domain_data = DomainData()
     assert hass.services.has_service(DOMAIN, SERVICE_LRU_STATS)
 
-    await hass.services.async_call(DOMAIN, SERVICE_LRU_STATS, blocking=True)
+    def _mock_by_type(type_):
+        if type_ == _LRU_CACHE_WRAPPER_OBJECT:
+            return [_dummy_test_lru_stats]
+        return [domain_data]
+
+    with patch("objgraph.by_type", side_effect=_mock_by_type):
+        await hass.services.async_call(DOMAIN, SERVICE_LRU_STATS, blocking=True)
 
     assert "DomainData" in caplog.text
     assert "(0, 0)" in caplog.text
     assert "_dummy_test_lru_stats" in caplog.text
     assert "CacheInfo" in caplog.text
-    del domain_data
-- 
GitLab