Skip to content

Commit 0bd2916

Browse files
committed
fix platform restrictions on test cases
1 parent 07fa8c4 commit 0bd2916

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

sdk/identity/azure-identity/tests/test_cli_credential.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,12 @@ def test_cli_not_installed_windows():
7575
AzureCliCredential().get_token("scope")
7676

7777

78-
@pytest.mark.parametrize("platform", ("darwin", "linux2", "win32"))
79-
def test_cannot_execute_shell(platform):
78+
def test_cannot_execute_shell():
8079
"""The credential should raise CredentialUnavailableError when the subprocess doesn't start"""
8180

82-
with mock.patch(AzureCliCredential.__module__ + ".sys.platform", platform):
83-
with mock.patch(CHECK_OUTPUT, mock.Mock(side_effect=OSError())):
84-
with pytest.raises(CredentialUnavailableError):
85-
AzureCliCredential().get_token("scope")
81+
with mock.patch(CHECK_OUTPUT, mock.Mock(side_effect=OSError())):
82+
with pytest.raises(CredentialUnavailableError):
83+
AzureCliCredential().get_token("scope")
8684

8785

8886
def test_not_logged_in():

sdk/identity/azure-identity/tests/test_cli_credential_async.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# ------------------------------------
55
from datetime import datetime
66
import json
7+
import sys
78
from unittest import mock
89

910
from azure.identity import CredentialUnavailableError
@@ -41,15 +42,15 @@ async def test_context_manager():
4142
pass
4243

4344

45+
@pytest.mark.skipif(not sys.platform.startswith("win"), reason="tests Windows-specific behavior")
4446
@pytest.mark.asyncio
4547
async def test_windows_fallback():
4648
"""The credential should fall back to the sync implementation when not using ProactorEventLoop on Windows"""
4749

4850
with mock.patch("azure.identity.AzureCliCredential.get_token") as fallback:
49-
with mock.patch(AzureCliCredential.__module__ + ".sys.platform", "win32"):
50-
with mock.patch(AzureCliCredential.__module__ + ".asyncio.get_event_loop"):
51-
credential = AzureCliCredential()
52-
await credential.get_token("scope")
51+
with mock.patch(AzureCliCredential.__module__ + ".asyncio.get_event_loop"):
52+
credential = AzureCliCredential()
53+
await credential.get_token("scope")
5354

5455
assert fallback.call_count == 1
5556

@@ -102,16 +103,14 @@ async def test_cli_not_installed_windows():
102103
await credential.get_token("scope")
103104

104105

105-
@pytest.mark.parametrize("platform", ("darwin", "linux2", "win32"))
106106
@pytest.mark.asyncio
107-
async def test_cannot_execute_shell(platform):
107+
async def test_cannot_execute_shell():
108108
"""The credential should raise CredentialUnavailableError when the subprocess doesn't start"""
109109

110-
with mock.patch(AzureCliCredential.__module__ + ".sys.platform", platform):
111-
with mock.patch(SUBPROCESS_EXEC, mock.Mock(side_effect=OSError())):
112-
with pytest.raises(CredentialUnavailableError):
113-
credential = AzureCliCredential()
114-
await credential.get_token("scope")
110+
with mock.patch(SUBPROCESS_EXEC, mock.Mock(side_effect=OSError())):
111+
with pytest.raises(CredentialUnavailableError):
112+
credential = AzureCliCredential()
113+
await credential.get_token("scope")
115114

116115

117116
@pytest.mark.asyncio

0 commit comments

Comments
 (0)