Skip to content

Commit

Permalink
test: fix lambda and trim getpass monkeypatch
Browse files Browse the repository at this point in the history
  • Loading branch information
maffettone committed Nov 20, 2024
1 parent 728b3fe commit ad30d1c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions tiled/_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ad30d1c

Please sign in to comment.