Skip to content

CredentialUnavailableError using Pytest and Async credentials #44932

@savvaki

Description

@savvaki
  • azure-identity:
  • 1.25.1:
  • Linux:
  • 3.13.7:

Describe the bug
CredentialUnavailableError is raised when I run repeated pytests using the Async DefaultAzureCredential. Note: about 80% of the tests work, but some fail to get the credential.

command_args = ['account', 'get-access-token', '--output', 'json', '--resource', 'https://ai.azure.com'], timeout = 10

    async def _run_command(command_args: List[str], timeout: int) -> str:
        # Ensure executable exists in PATH first. This avoids a subprocess call that would fail anyway.
        if sys.platform.startswith("win"):
            # On Windows, the expected executable is az.cmd, so we check for that first, falling back to 'az' in case.
            az_path = shutil.which(EXECUTABLE_NAME + ".cmd") or shutil.which(EXECUTABLE_NAME)
        else:
            az_path = shutil.which(EXECUTABLE_NAME)
        if not az_path:
            raise CredentialUnavailableError(message=CLI_NOT_FOUND)
    
        args = [az_path] + command_args
        working_directory = get_safe_working_dir()
        try:
            _LOGGER.debug("Executing subprocess with the following arguments %s", args)
            proc = await asyncio.create_subprocess_exec(
                *args,
                stdout=asyncio.subprocess.PIPE,
                stderr=asyncio.subprocess.PIPE,
                stdin=asyncio.subprocess.DEVNULL,
                cwd=working_directory,
                env=dict(os.environ, AZURE_CORE_NO_COLOR="true"),
            )
            stdout_b, stderr_b = await asyncio.wait_for(proc.communicate(), timeout)
            output = stdout_b.decode()
            stderr = stderr_b.decode()
        except asyncio.TimeoutError as ex:
            proc.kill()
>           raise CredentialUnavailableError(message="Timed out waiting for Azure CLI") from ex
E           azure.identity._exceptions.CredentialUnavailableError: Timed out waiting for Azure CLI

Metadata

Metadata

Labels

Azure.Identitycustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

Status

Untriaged

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions