FIX: make azure-core import optional in test_008_auth.py - #705
FIX: make azure-core import optional in test_008_auth.py#705Jahnvi Thakkar (jahnvi480) wants to merge 2 commits into
Conversation
…n works without azure
There was a problem hiding this comment.
🟢 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 TokenCredentialimport in atry/except ImportError, falling back toTokenCredential = None. - Marked the two
TokenCredentialProtocol runtime-check tests with@pytest.mark.skipif(TokenCredential is None, ...)so they only run whenazure-coreis 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.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changesNo 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.2%
mssql_python.__init__.py: 77.6%
mssql_python.row.py: 77.6%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 81.4%
mssql_python.pybind.connection.connection.cpp: 83.7%
mssql_python.logging.py: 85.5%🔗 Quick Links
|
AB#46836
Summary
tests/test_008_auth.pyadded a top-levelfrom azure.core.credentials import TokenCredential(introduced with thetoken_providerwork in #603). That import runs at module-collection time — before the autousesetup_azure_identityfixture injects its mockazure.*modules intosys.modules— so in build/validation stages that install a minimal dependency set (noazure-identity/azure-core), pytest aborts the whole module with:This wraps only that one top-level import in a
try/except ImportErrorguard (falling back toTokenCredential = None) so the module collects even whenazure-coreis absent. The two tests inTestTokenProviderProtocolthat genuinely need the realruntime_checkableProtocol are marked@pytest.mark.skipif(TokenCredential is None, ...); the third scope-constant test does not useTokenCredentialand continues to run.All other
azure.*imports in this file are function-local and already resolve to the fixture'ssys.modulesmocks, so no other changes are needed. Whenazure-coreis installed (the normal path), behavior is unchanged and both protocol tests run.No production code is touched — test-only hardening.