title: How can I test a loop with multiple input calls?
body: <p>I'm trying to test a fuction that dependets a of multiple user inputs to return some value.</p>
  
  <p>I've already looked for multiples unswers here but none was able to resolve my problem. I saw things with parametrize, mock and monkey patch but none helped. I think a lot is because I don't clearly understood the concepts behind what was being done and I couldn't adapt to my problem. I saw suggestion of using external file for this but I don't wont to depend on that. I'm trying with pytest and python 3.7.3</p>
  
  <p>The function that I want to test is something like this</p>
  
  <pre class="lang-py prettyprint-override"><code>def function():
      usr_input = input('please enter a number: ')
      while True:
          if int(usr_input) &lt; 5:
              usr_input = input('please, enter a value less then 5: ')
          else:
              break
      return usr_input
  </code></pre>
  
  <p>I want to know how can I pass two input values to test the function when the inserted value is not valid. Example: Send value 6 and 2, make an assert expecting value 2 and pass the test. My others tests look like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>def test_input(monkeypatch):
      monkeypatch.setattr('builtins.input', lambda x: 6)
      test = function()
      assert test == 2
  </code></pre>
  
  <p>but, for this case, they loop. It's possible to do this only with parametrize or other simple code?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I added a int() in my "if", as wim pointed in the accepted answer, just to prevent any confusion for future readers. I'm assuming the cast is possible.</p>