|
4 | 4 | # ------------------------------------ |
5 | 5 | from datetime import datetime |
6 | 6 | import json |
| 7 | +import sys |
7 | 8 | from unittest import mock |
8 | 9 |
|
9 | 10 | from azure.identity import CredentialUnavailableError |
@@ -41,15 +42,15 @@ async def test_context_manager(): |
41 | 42 | pass |
42 | 43 |
|
43 | 44 |
|
| 45 | +@pytest.mark.skipif(not sys.platform.startswith("win"), reason="tests Windows-specific behavior") |
44 | 46 | @pytest.mark.asyncio |
45 | 47 | async def test_windows_fallback(): |
46 | 48 | """The credential should fall back to the sync implementation when not using ProactorEventLoop on Windows""" |
47 | 49 |
|
48 | 50 | 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") |
53 | 54 |
|
54 | 55 | assert fallback.call_count == 1 |
55 | 56 |
|
@@ -102,16 +103,14 @@ async def test_cli_not_installed_windows(): |
102 | 103 | await credential.get_token("scope") |
103 | 104 |
|
104 | 105 |
|
105 | | -@pytest.mark.parametrize("platform", ("darwin", "linux2", "win32")) |
106 | 106 | @pytest.mark.asyncio |
107 | | -async def test_cannot_execute_shell(platform): |
| 107 | +async def test_cannot_execute_shell(): |
108 | 108 | """The credential should raise CredentialUnavailableError when the subprocess doesn't start""" |
109 | 109 |
|
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") |
115 | 114 |
|
116 | 115 |
|
117 | 116 | @pytest.mark.asyncio |
|
0 commit comments