I'm wanting to mock user input during a test and it seems that monkeypatching is the way to do it. However, most materials online use monkeypatching in relation to classes (I think because monkeypatching is mainly for use on objects?).
Is there a way to monkeypatch for just functions? Or is there an alternative to using MP when wanting to test a function that requires user input?
app.py
def my_name():
y = input("What is your name?")
return(y)
test.py
def test_my_name(monkeypatch):
def mock_my_name():
return("Antony")
monkeypatch.setattr(y, mock_my_name)
x = my_name()
assert x == "Antony"
Running the above gets the following error: 'OSError: pytest: reading from stdin while output is captured! Consider using '-s'. '
I'm also unsure what this -s flag is.