From ad30d1cb38da9dfc3f7c424bac1fb8be92c5f6ce Mon Sep 17 00:00:00 2001 From: maffettone Date: Wed, 20 Nov 2024 18:21:16 -0500 Subject: [PATCH] test: fix lambda and trim getpass monkeypatch --- tiled/_tests/utils.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tiled/_tests/utils.py b/tiled/_tests/utils.py index 97a1b62eb..13440e8ef 100644 --- a/tiled/_tests/utils.py +++ b/tiled/_tests/utils.py @@ -55,21 +55,18 @@ async def temp_postgres(uri): @contextlib.contextmanager def enter_username_password(username, password): """ - Override getpass, or prompt_for_credentials with username only + Override getpass, when prompt_for_credentials with username only used like: - >>> with enter_password(...): - ... # Run code that calls getpass.getpass(). + >>> with enter_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 - original_getpass = getpass.getpass context.PROMPT_FOR_REAUTHENTICATION = True - context.prompt_for_credentials = lambda u: username, password - setattr(getpass, "getpass", lambda: password) + context.prompt_for_credentials = lambda u, p: (username, password) yield - setattr(getpass, "getpass", original_getpass) context.PROMPT_FOR_REAUTHENTICATION = original_prompt context.prompt_for_credentials = original_credentials