Skip to content

Commit 2a49088

Browse files
comments
1 parent e68637d commit 2a49088

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/test_shadowed_module.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def test_shadowed_modules_when_importing_integrations(
9292
"""
9393
module_path = f"sentry_sdk.integrations.{integration_submodule_name}"
9494
try:
95+
# If importing the integration succeeds in the current environment, assume
96+
# that the integration has no non-standard imports.
9597
importlib.import_module(module_path)
9698
return
9799
except integrations.DidNotEnable:
@@ -100,8 +102,15 @@ def test_shadowed_modules_when_importing_integrations(
100102
tree = ast.parse(source, filename=spec.origin)
101103
integration_dependencies = find_unrecognized_dependencies(tree)
102104

105+
# For each non-standard import, create an empty shadow module to
106+
# emulate an empty "agents.py" or analogous local module that
107+
# shadows the package.
103108
for dependency in integration_dependencies:
104109
sys.modules[dependency] = types.ModuleType(dependency)
110+
111+
# Importing the integration must raise DidNotEnable, since the
112+
# SDK catches the exception type when attempting to activate
113+
# auto-enabling integrations.
105114
with pytest.raises(integrations.DidNotEnable):
106115
importlib.import_module(module_path)
107116

0 commit comments

Comments
 (0)