diff --git a/tiled/_tests/utils.py b/tiled/_tests/utils.py index 2e90629e5..ffbe8d2d0 100644 --- a/tiled/_tests/utils.py +++ b/tiled/_tests/utils.py @@ -61,11 +61,12 @@ def enter_username_password(username, password): ... # Run code that calls prompt_for_credentials and subsequently getpass.getpass(). """ + original_prompt = context.PROMPT_FOR_REAUTHENTICATION + original_credentials = context.prompt_for_credentials + context.PROMPT_FOR_REAUTHENTICATION = True + context.prompt_for_credentials = lambda u, p: (username, password) try: - original_prompt = context.PROMPT_FOR_REAUTHENTICATION - original_credentials = context.prompt_for_credentials - context.PROMPT_FOR_REAUTHENTICATION = True - context.prompt_for_credentials = lambda u, p: (username, password) + # Ensures that raise in calling routine does not prevent context from being exited. yield finally: context.PROMPT_FOR_REAUTHENTICATION = original_prompt