Python Forum

Full Version: unit testing a method that asks two user inputs() in console
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am really struggling to unittest the following simple method:

def add():
         a = int(input('Enter first number '))
         b= int(input('Enter second number '))
         return a + b
I tried the following but it failed:


import unittest

from unittest.mock import patch


@patch('builtins.input', return_value='2')
@patch('builtins.input', return_value='3')
def test_add(self,  a, b ):
    self.assertEqual(result, 5)