I am a novice python coder on my greatest of days. I am in a class and using pytest to wrap my head around TDD. Some of the functions in this code (based off of Dane Hillard's Bark) calls a function that prompts the user for input. I need to automate the input of the nested function.
def get_user_input(label, required=True):
value = input(f"{label}: ") or None
while required and not value:
value = input(f"{label}: ") or None
return value
def get_new_bookmark_data():
return {
"title": get_user_input("Title"),
"url": get_user_input("URL"),
"notes": get_user_input("Notes", required=False),
}
I can't even wrap my head around how I should deal with test_get_user_input() much less the bookmark.
Here are some of the things I have tried:
def test_get_user_input(monkeypatch):
uInput = 'a'
monkeypatch.setattr('sys.stdin', uInput)
assert barky.get_user_input() == 'A'
I'm just not there yet. Here is my repo: https://github.com/impilcature/Green-CIDM6330