test: Assert setup_once() only raises DidNotEnable with shadowed dependencies#5478
test: Assert setup_once() only raises DidNotEnable with shadowed dependencies#5478alexander-alderman-webb wants to merge 5 commits intomasterfrom
setup_once() only raises DidNotEnable with shadowed dependencies#5478Conversation
…th shadowed dependencies
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.67s All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 13698 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
setup_once() only raises DidNotEnable in integrations with shadowed dependenciessetup_once() only raises DidNotEnable with shadowed dependencies
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| import_path = ".".join(("sentry_sdk", "integrations", *parts)) | ||
|
|
||
| integration_dependencies = set() | ||
| for py_file in pathlib.Path(module_path).rglob("*.py"): |
There was a problem hiding this comment.
Path construction fails for single-file integrations
High Severity
The module_path is constructed without the .py extension for single-file integrations like aiohttp. When rglob is called on sentry_sdk/integrations/aiohttp (a non-existent directory since the actual file is aiohttp.py), it returns an empty iterator. This causes integration_dependencies to remain empty, making the test ineffective for single-file integrations—it doesn't actually test them with shadowed dependencies.
| # auto-enabling integrations. | ||
| with pytest.raises(integrations.DidNotEnable): | ||
| importlib.import_module(module_path) | ||
| importlib.import_module(import_path) |
There was a problem hiding this comment.
Shadow modules leak if reimport assertion fails
Medium Severity
If the pytest.raises assertion fails because importlib.import_module(import_path) doesn't raise DidNotEnable as expected, the assertion failure exception prevents the cleanup code at lines 111-112 from executing. This leaves shadow modules in sys.modules that could interfere with subsequent tests.


Description
Extend shadowed module test to verify that imports are correctly gated in
setup_once()methods.We only considered exceptions when importing the module containing an integration in #5140. An
AttributeErrordue to a shadowed import insidesetup_once()led to a new issue #5298.The following test failures are raised without the added ignore list.
Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)