diff --git a/gerrit_util.py b/gerrit_util.py index 3b9470c98..9801765ed 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -11,6 +11,7 @@ from __future__ import annotations import base64 import contextlib +import functools import http.cookiejar import json import logging @@ -173,6 +174,7 @@ class SSOHelper(object): ssoHelper = SSOHelper() +@functools.lru_cache(maxsize=None) def ShouldUseSSO(host: str, email: str) -> bool: """Return True if we should use SSO for the given Gerrit host and user.""" LOGGER.debug("Determining whether we should use SSO...") diff --git a/tests/gerrit_util_test.py b/tests/gerrit_util_test.py index 4d92842f2..2e05cf3b9 100755 --- a/tests/gerrit_util_test.py +++ b/tests/gerrit_util_test.py @@ -731,17 +731,15 @@ class ShouldUseSSOTest(unittest.TestCase): def setUp(self) -> None: self.newauth = mock.patch('newauth.Enabled', return_value=True) self.newauth.start() - self.cwd = mock.patch('os.getcwd', return_value='/fake/cwd') self.cwd.start() - self.sso = mock.patch('gerrit_util.ssoHelper.find_cmd', return_value='/fake/git-remote-sso') self.sso.start() - scm_mock.GIT(self) - self.addCleanup(mock.patch.stopall) + + gerrit_util.ShouldUseSSO.cache_clear() return super().setUp() def tearDown(self) -> None: