From 39f1d0deee4a2f18756df1a6155e3b8c632f054e Mon Sep 17 00:00:00 2001 From: maffettone Date: Mon, 25 Nov 2024 06:55:42 -0500 Subject: [PATCH] refactor: move initial context setting out of try block --- tiled/_tests/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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