Skip to content

Handle namespace packages in the import test - #2424

Merged
Robert Yokota (rayokota) merged 1 commit into
confluentinc:masterfrom
pylaterreur:fix/test-imports-namespace-packages
Nov 13, 2026
Merged

Robert Yokota (rayokota) merged 1 commit into
confluentinc:masterfrom
pylaterreur:fix/test-imports-namespace-packages

Conversation

@pylaterreur

Copy link
Copy Markdown
Contributor

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:

  • only azure-core installed: azure_driver fails with No module named 'azure.identity'; only azure-identity: No module named 'azure.keyvault';
  • tink installed, which brings protobuf and so the google namespace: gcp_client fails with No module named 'google.cloud' and gcp_driver with No module named 'google.oauth2';
  • with googleapis-common-protos as well, which provides google.cloud: cannot import name 'kms_v1' from 'google.cloud' (unknown location), a plain ImportError;
  • only protobuf installed: No module named 'google.type'.

The test now also skips a missing portion of a namespace package: a ModuleNotFoundError whose parent is a namespace package, or the plain ImportError naming a namespace package that from <namespace package> import <portion> raises. An ImportError that a dependency re-raises with raise ... from (tink does this for its extras) is judged 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.

Checklist

  • Contains customer facing changes? Including API/behavior changes
    • No, test only.
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • The change is to a test; see below for how it was checked.

References

Follow-up to #2416: #2416 (comment)

Test & Review

  • Python 3.9.25, 3.11.16 and 3.14.7 with requirements/requirements-schemaregistry.txt plus only one of azure-core, azure-identity, tink, tink and googleapis-common-protos, or protobuf; and 3.15.0rc2 with azure-core and the protobuf extra: the test on master fails in each, this version passes.
  • Python 3.9 to 3.14 and 3.14t with requirements/requirements-tests-install.txt (the nogil variant on 3.14t; on 3.14, google-re2 1.1.20251105, as the pinned google-re2<1.1.20251105 has no cp314 wheels), and with only pytest: passes.
  • Modules injected into the installed package on 3.9, 3.11, 3.14 and 3.14t: a missing symbol or submodule of an installed package, a missing confluent_kafka module or symbol, a circular import, another exception, a nameless ImportError and 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 the azure_driver.py from before Fix circular import in the Azure KMS driver #2416, the test still fails with the circular import.
  • Python 3.11.16, pytest tests --ignore=tests/integration: 2554 passed, 16 skipped. tools/style-format.sh on all tracked Python files, flake8, mypy src/confluent_kafka and tools/unasync.py --check pass.

Open questions / Follow-ups

  • confluent_kafka.kafkatest.verifiable_consumer and verifiable_producer are still skipped: they import verifiable_client as a top-level module, which the test cannot tell apart from a package that is not installed. For the same reason python -m confluent_kafka.kafkatest.verifiable_consumer, as documented in kafkatest/README.md and used in kafkatest/globals.json and kafkatest/deploy.sh, fails with ModuleNotFoundError: No module named 'verifiable_client'. Importing confluent_kafka.kafkatest.verifiable_client instead would fix both; it is not part of this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN

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
@confluent-cla-assistant

Copy link
Copy Markdown

🎉 All Contributor License Agreements have been signed. Ready to merge.
✅ pylaterreur
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

@rayokota

Copy link
Copy Markdown
Member

/sem-approve

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@rayokota Robert Yokota (rayokota) added the component:schema-registry Any schema registry related isues rather than kafka isolated ones label Nov 13, 2026

@rayokota Robert Yokota (rayokota) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rayokota
Robert Yokota (rayokota) merged commit 2ad4943 into confluentinc:master Nov 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:schema-registry Any schema registry related isues rather than kafka isolated ones

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants