Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

Using pytest to check the input prompt

$
0
0

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.out

The 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()`?


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>