From 8f2f94b7e52e75cb2ada77cf510489329edf6964 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 6 Jan 2025 14:29:37 +0530 Subject: [PATCH] test: make redis query count util work with any redis instance --- frappe/tests/classes/integration_test_case.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frappe/tests/classes/integration_test_case.py b/frappe/tests/classes/integration_test_case.py index c438ac5358..2d44c4a514 100644 --- a/frappe/tests/classes/integration_test_case.py +++ b/frappe/tests/classes/integration_test_case.py @@ -130,25 +130,27 @@ class IntegrationTestCase(UnitTestCase): @contextmanager def assertRedisCallCounts(self, count: int) -> AbstractContextManager[None]: + from frappe.utils.redis_wrapper import RedisWrapper + commands = [] def execute_command_and_count(*args, **kwargs): ret = orig_execute(*args, **kwargs) key_len = 2 - if "H" in args[0]: + if "H" in args[1]: key_len = 3 - commands.append((args)[:key_len]) + commands.append((args)[1 : key_len + 1]) return ret try: - orig_execute = frappe.cache.execute_command - frappe.cache.execute_command = execute_command_and_count + orig_execute = RedisWrapper.execute_command + RedisWrapper.execute_command = execute_command_and_count yield self.assertLessEqual( len(commands), count, msg="commands executed: \n" + "\n".join(str(c) for c in commands) ) finally: - frappe.cache.execute_command = orig_execute + RedisWrapper.execute_command = orig_execute @contextmanager def assertRowsRead(self, count: int) -> AbstractContextManager[None]: