Skip to content

FIX: make azure-core import optional in test_008_auth.py - #705

Merged
Jahnvi Thakkar (jahnvi480) merged 2 commits into
mainfrom
jahnvi/fix-test008-azure-optional-import
Aug 6, 2026
Merged

FIX: make azure-core import optional in test_008_auth.py#705
Jahnvi Thakkar (jahnvi480) merged 2 commits into
mainfrom
jahnvi/fix-test008-azure-optional-import

Conversation

@jahnvi480

@jahnvi480 Jahnvi Thakkar (jahnvi480) commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

AB#46836

Summary

tests/test_008_auth.py added a top-level from azure.core.credentials import TokenCredential (introduced with the token_provider work in #603). That import runs at module-collection time — before the autouse setup_azure_identity fixture injects its mock azure.* modules into sys.modules — so in build/validation stages that install a minimal dependency set (no azure-identity/azure-core), pytest aborts the whole module with:

ModuleNotFoundError: No module named 'azure'
  tests/test_008_auth.py:32: in <module>
    from azure.core.credentials import TokenCredential

This wraps only that one top-level import in a try/except ImportError guard (falling back to TokenCredential = None) so the module collects even when azure-core is absent. The two tests in TestTokenProviderProtocol that genuinely need the real runtime_checkable Protocol are marked @pytest.mark.skipif(TokenCredential is None, ...); the third scope-constant test does not use TokenCredential and continues to run.

All other azure.* imports in this file are function-local and already resolve to the fixture's sys.modules mocks, so no other changes are needed. When azure-core is installed (the normal path), behavior is unchanged and both protocol tests run.

No production code is touched — test-only hardening.

Copilot AI lite review requested due to automatic review settings August 5, 2026 16:05
@github-actions github-actions Bot added the pr-size: small Minimal code update label Aug 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Ready to approve

The change is a small, test-only guard that prevents collection-time failures without altering production behavior.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR hardens the tests/test_008_auth.py module collection path by making the azure-core dependency optional at import time, preventing pytest from aborting in minimal dependency environments (no azure packages installed) while preserving existing behavior when azure-core is available.

Changes:

  • Wrapped the top-level from azure.core.credentials import TokenCredential import in a try/except ImportError, falling back to TokenCredential = None.
  • Marked the two TokenCredential Protocol runtime-check tests with @pytest.mark.skipif(TokenCredential is None, ...) so they only run when azure-core is installed.
File summaries
File Description
tests/test_008_auth.py Avoids module import failure when azure-core is absent; conditionally skips TokenCredential-dependent tests.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

82%


📈 Total Lines Covered: 7353 out of 8961
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

No lines with coverage information in this diff.


📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 59.9%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 76.3%
mssql_python.__init__.py: 77.6%
mssql_python.row.py: 77.6%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection.cpp: 83.7%
mssql_python.logging.py: 85.5%
mssql_python.connection.py: 85.7%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

@jahnvi480
Jahnvi Thakkar (jahnvi480) merged commit 5c311e2 into main Aug 6, 2026
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: small Minimal code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants