Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 unit testing a method that asks two user inputs() in console
#1
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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Perminantly saving user inputs + being able to retrieve it ThatOneGuyNoOneKnowsCodes 1 321 Oct-23-2019, 11:28 PM
Last Post: DT2000
  Unit testing - AssertRaises kerzol81 3 332 Oct-07-2019, 10:35 AM
Last Post: buran
  Trying to prompt user for 2 inputs on one line pythonprogrammer 2 338 Sep-15-2019, 04:41 PM
Last Post: snippsat
  user inputs in constructing a dictionary Exsul 3 480 Apr-10-2019, 12:25 PM
Last Post: ichabod801
  How to use a string method on user input Exsul 2 510 Mar-17-2019, 08:12 PM
Last Post: Exsul
  User defined method as variable or argument AeranicusCascadia 5 1,417 Dec-13-2017, 04:47 PM
Last Post: AeranicusCascadia
  Discord bot that asks questions and based on response answers or asks more questions absinthium 1 3,064 Nov-25-2017, 06:21 AM
Last Post: heiner55
  Would you unit test __init__ method? kilthar 1 10,431 Oct-18-2017, 05:31 PM
Last Post: snippsat
  Unit testing mp3909 1 1,185 Oct-15-2017, 03:48 PM
Last Post: metulburr
  question regarding user Inputs cibb 10 2,894 Apr-04-2017, 03:34 AM
Last Post: alicarlos13

Forum Jump:


Users browsing this thread: 1 Guest(s)