Imagine I have a Python function that goes something like this:
def myFunction(argument: str) -> None: doStuff() result = input(f'{complicated_logic_involving_argument}: ') doOtherStuff()I want to test the results of myFunction(), but I also want to test that the complicated prompt displays correctly for each possible argument.
The problem is when I try
@mark.parametrize(('argument', 'prompt'), ( ('firstValue', 'Expected Prompt'),))def test_myFunction(argument: str, prompt: str, monkeypatch, capsys) -> None: monkeypatch.setattr('builtins.input', lambda _: 'whatever') myFunction(argument) # THIS IS WHERE MY TEST CODE FAILS! snapshot = capsys.readouterr() assert prompt in snapshot.outThe actual prompt doesn't seem to go to either snapshot.out, or snapshot.err. I have also tried using capfd, but no bliss.
Any on out o capture the prompt of input()`?