-
Notifications
You must be signed in to change notification settings - Fork 571
test: Import integrations with empty shadow modules #5150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
tests/test_shadowed_module.py
Outdated
| # Temporary skip list | ||
| if submodule_name in ( | ||
| "clickhouse_driver", | ||
| "grpc", | ||
| "litellm", | ||
| "opentelemetry", | ||
| "pure_eval", | ||
| "ray", | ||
| "trytond", | ||
| "typer", | ||
| ): | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we merge this test, my plan is to remove integrations from the skip list one-by-one.
tests/test_shadowed_module.py
Outdated
| sys.modules[dependency] = types.ModuleType(dependency) | ||
| with pytest.raises(integrations.DidNotEnable): | ||
| importlib.import_module(module_path) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to parametrize the test and fork it because messing with .sys.modules and importing can cause side-effects and influence other tests otherwise
edit: I don't like adding more forked tests. I'll move the test into it's own tox environment so there's no risk of messing with the behavior of other tests when removing the forking.
Add a test parametrized on our integrations. The test detects if the integration imports modules not in the standard library, and if so, verifies that importing the integration with an empty shadow module raises a
DidNotEnableexception.Motivation
Adding integrations to be auto-enabling can cause SDK crashes in two specific cases we encountered at the end of last week:
ImportErrorwhen we patch something that does not yet exist; oragents.pyin the environment shadows the import and causes anImportErrorif the auto-activation still triggers.All integrations with poorly gated imports are not auto-enabling, but some affected integrations are new (e.g., litellm).
Issues
Closes #5140
Reminders
tox -e linters.feat:,fix:,ref:,meta:)