fix get_fixture function

This commit is contained in:
Jonathan Wren 2023-02-25 14:57:51 -08:00
parent 9bb92707d0
commit 3956b75698
No known key found for this signature in database
4 changed files with 17 additions and 10 deletions

View file

@ -231,13 +231,15 @@ def mock_user_input(request, password_input, stdin_input):
def _mock_user_input():
# user_input needs to be here because we don't know it until cli_run starts
user_input = get_fixture(request, "all_input", None)
if user_input is None:
user_input = Exception("Unexpected call for user input")
else:
user_input = iter(user_input.splitlines())
def mock_console_input(**kwargs):
if kwargs["password"] and not isinstance(password_input, Exception):
pw = kwargs.get("password", False)
if pw and not isinstance(password_input, Exception):
return password_input
if isinstance(user_input, Iterable):
@ -246,7 +248,7 @@ def mock_user_input(request, password_input, stdin_input):
return "" if input_line == r"\n" else input_line
# exceptions
return user_input if not kwargs["password"] else password_input
return user_input if not pw else password_input
mock_console = Mock(wraps=Console(stderr=True))
mock_console.input = Mock(side_effect=mock_console_input)

View file

@ -77,7 +77,7 @@ def spy_wrapper(wrapped_function):
def get_fixture(request, name, default=None):
result = default
if name in request.node.fixturenames:
result = request.getfixturevalue(name)
return result
try:
return request.getfixturevalue(name)
except LookupError:
return default