From 81ac80321ef9c0102904340658add89a1c4ae6aa Mon Sep 17 00:00:00 2001 From: Dave Page Date: Mon, 17 Aug 2026 16:54:47 +0100 Subject: [PATCH] fix: make the auth gating test independent of import order The test added in #10240 fails in a full run, though it passes when the authenticate package is tested on its own: FAIL: runTest (pgadmin.authenticate.tests.test_auth_gating .AuthSourceGatingTestCase) AssertionError: 'oauth2' not found in ['internal', 'kerberos', 'ldap', 'webserver'] It cleared sys.modules for each provider and expected load_modules(), which reaches them with "from . import ", to import and hence re-register them. That is not enough: IMPORT_FROM finds the attribute already set on the parent package by whichever earlier test imported the module, and returns the previous module object without re-executing it, so the provider never re-registers itself. Only oauth2 was affected, because it is the one provider imported earlier in a full run, by the tests under browser/tests. Nothing pre-imports it when the authenticate package is run alone, which is why the narrow run passed and CI did not. Drop the attribute from the parent package alongside the sys.modules entry, so the import genuinely happens again. Verified with the full suite as CI runs it, python regression/runtests.py --exclude feature_tests: both scenarios pass and the runner's own exit status is clean, with the only remaining failure a local config-directory permissions check that depends on the developer's config_local.py. --- web/pgadmin/authenticate/tests/test_auth_gating.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web/pgadmin/authenticate/tests/test_auth_gating.py b/web/pgadmin/authenticate/tests/test_auth_gating.py index 7c1d5adb1..65080754a 100644 --- a/web/pgadmin/authenticate/tests/test_auth_gating.py +++ b/web/pgadmin/authenticate/tests/test_auth_gating.py @@ -56,8 +56,19 @@ class AuthSourceGatingTestCase(BaseTestGenerator): """Empty the registry and drop the external provider modules, so that load_modules() is observed importing them (or not) from scratch. """ - for module in EXTERNAL_MODULES: + import pgadmin.authenticate as auth_package + + for source, module in zip(EXTERNAL_SOURCES, EXTERNAL_MODULES): sys.modules.pop(module, None) + # Clearing sys.modules alone is not enough. load_modules() reaches + # these with "from . import ", which finds the attribute + # already set on the parent package by whichever earlier test + # imported it, and so returns the previous module object without + # re-executing it. The provider then never re-registers itself and + # the registry looks empty for that one alone. Dropping the + # attribute as well forces the real import. + if hasattr(auth_package, source): + delattr(auth_package, source) AuthSourceRegistry._registry = dict() AuthSourceRegistry._objects = dict()