title: How efficiently unit test a function with multiple input calls?
body: <p>I have a unit test that works as intended, however I feel that this is not the best way to test multiple inputs with pytest. It definitely violates the DRY principle. I thinking there's a better way to go about this but I can't figure out what. I'm also not sure what to actually do with the mock. It's not used but it has to be there (see 'mock_choice' parameter in the function in the code below).</p>
  
  <p>I thought perhaps looping through the calls would work but that didn't work as intended. I really couldn't figure out another way besides using side_effects and calling four times to test to make sure I get return value as I intended. </p>
  
  <p><strong>Function To Test</strong></p>
  
  <pre><code>def export_options():
      while True:
          try:
              choice = int(input("\nPlease make a selection"))
              if choice in ([option for option in range(1, 5)]):
                  return choice  # This what I'm testing
              else:
                  print("\nNot a valid selection\n")
          except ValueError as err:
              print("Please enter an integer")
  </code></pre>
  
  <p><strong>Test Function</strong></p>
  
  <pre><code>@mock.patch('realestate.app.user_inputs.input', side_effect=[1, 2, 3, 4])
  def test_export_options_valid_choice(mock_choice): # mock_choice needs to be here but isn't used!
  
      export_option = user_inputs.export_options()
      assert export_option == 1
  
      export_option = user_inputs.export_options()
      assert export_option == 2
  
      export_option = user_inputs.export_options()
      assert export_option == 3
  
      export_option = user_inputs.export_options()
      assert export_option == 4
  </code></pre>
  
  <p>The test works. It passes as the function returns all values between 1 and 4. However, because the code is very repetitive, I would like to know if there's a better way to test multiple input calls as I would like to apply the same to future tests.</p>