mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-08-17 16:34:44 -05:00
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 <provider>", 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.
This commit is contained in:
@@ -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 <provider>", 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()
|
||||
|
||||
Reference in New Issue
Block a user