Repository navigation
Handle namespace packages in the import test - #2424
Merged
Robert Yokota (rayokota) merged 1 commit intoNov 13, 2026
Merged
Robert Yokota (rayokota) merged 1 commit into
Robert Yokota (rayokota) merged 1 commit into
Conversation
tests/test_imports.py skips a module whose import fails because an optional dependency is not installed, but it only recognized a missing top-level package. A missing portion of a namespace package made it fail whenever another portion was installed: with only azure-core installed, azure_driver fails with "No module named 'azure.identity'", and with tink installed, which brings protobuf and so the google namespace, gcp_client fails with "No module named 'google.cloud'", or, when googleapis-common-protos provides google.cloud, with "cannot import name 'kms_v1' from 'google.cloud' (unknown location)". Also skip a missing portion of a namespace package, including the plain ImportError that "from <namespace package> import <portion>" raises, and judge an ImportError that a dependency re-raises (as tink does for its extras) by its cause. A missing submodule or symbol of an installed regular package, or a missing confluent_kafka module, still fails, and a missing typing_extensions (required on Python < 3.11) or standard library module (Python 3.10+) now fails instead of being skipped. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
Pierre-Yves Le Borgne (pylaterreur)
requested review from
a team and
Matthew Seal (MSeal)
as code owners
November 12, 2026 19:31
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
2 tasks done
Member
|
/sem-approve |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the test-only import smoke-test update.
No open issues 🎉
What changed in this PR
Updates the import smoke test introduced in #2416 to handle partially installed namespace packages without hiding failures from required dependencies or installed regular packages. This is a test-only change.
Changes:
- Recognizes missing namespace portions and checks chained import errors when deciding whether to skip a module.
- Prevents missing
confluent_kafka,typing_extensions, and recognized standard-library modules from being treated as optional dependencies. - Consolidates exception handling while retaining tracebacks for import failures.
| File | Description |
|---|---|
tests/test_imports.py |
Adds namespace-aware optional-dependency detection and consolidates import-error handling. |
Review effort: Balanced
Robert Yokota (rayokota)
approved these changes
Nov 13, 2026
Robert Yokota (rayokota)
left a comment
Member
There was a problem hiding this comment.
Thanks Pierre-Yves Le Borgne (@pylaterreur) , LGTM
Robert Yokota (rayokota)
merged commit Nov 13, 2026
2ad4943
into
confluentinc:master
3 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
tests/test_imports.py(added in #2416) skips a module whose import fails because an optional dependency is not installed, but it only recognized a missing top-level package. As Copilot pointed out on #2416, it failed when one portion of a namespace package was installed and another was not:azure-coreinstalled:azure_driverfails withNo module named 'azure.identity'; onlyazure-identity:No module named 'azure.keyvault';tinkinstalled, which brings protobuf and so thegooglenamespace:gcp_clientfails withNo module named 'google.cloud'andgcp_driverwithNo module named 'google.oauth2';google.cloud:cannot import name 'kms_v1' from 'google.cloud' (unknown location), a plainImportError;protobufinstalled:No module named 'google.type'.The test now also skips a missing portion of a namespace package: a
ModuleNotFoundErrorwhose parent is a namespace package, or the plainImportErrornaming a namespace package thatfrom <namespace package> import <portion>raises. AnImportErrorthat a dependency re-raises withraise ... from(tink does this for its extras) is judged by its cause. A missing submodule or symbol of an installed regular package, or a missingconfluent_kafkamodule, still fails, and a missingtyping_extensions(required on Python < 3.11) or standard library module (Python 3.10+) now fails instead of being skipped.Checklist
References
Follow-up to #2416: #2416 (comment)
Test & Review
requirements/requirements-schemaregistry.txtplus only one ofazure-core,azure-identity,tink,tinkandgoogleapis-common-protos, orprotobuf; and 3.15.0rc2 withazure-coreand the protobuf extra: the test on master fails in each, this version passes.requirements/requirements-tests-install.txt(the nogil variant on 3.14t; on 3.14, google-re2 1.1.20251105, as the pinnedgoogle-re2<1.1.20251105has no cp314 wheels), and with onlypytest: passes.confluent_kafkamodule or symbol, a circular import, another exception, a namelessImportErrorand a re-raised missing symbol still fail; an uninstalled package, a missing namespace portion (import google.x,from google.cloud import x,import azure.keyvault.x) and re-raised versions of those are skipped. With theazure_driver.pyfrom before Fix circular import in the Azure KMS driver #2416, the test still fails with the circular import.pytest tests --ignore=tests/integration: 2554 passed, 16 skipped.tools/style-format.shon all tracked Python files,flake8,mypy src/confluent_kafkaandtools/unasync.py --checkpass.Open questions / Follow-ups
confluent_kafka.kafkatest.verifiable_consumerandverifiable_producerare still skipped: theyimport verifiable_clientas a top-level module, which the test cannot tell apart from a package that is not installed. For the same reasonpython -m confluent_kafka.kafkatest.verifiable_consumer, as documented inkafkatest/README.mdand used inkafkatest/globals.jsonandkafkatest/deploy.sh, fails withModuleNotFoundError: No module named 'verifiable_client'. Importingconfluent_kafka.kafkatest.verifiable_clientinstead would fix both; it is not part of this PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN