Python Forum
unit testing a method that asks two user inputs() in console
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unit Testing Set Up and Use RockBlok 2 425 Jan-08-2024, 07:43 PM
Last Post: deanhystad
  How to write a response if a user inputs a string horuscope42 3 2,220 Apr-29-2020, 03:39 PM
Last Post: deanhystad
  Remove function and unit test ftg 5 3,535 Jan-07-2020, 03:10 PM
Last Post: ndc85430
  Odd Unit Test Behavior ichabod801 3 2,582 Jan-02-2020, 03:34 PM
Last Post: ichabod801
  Perminantly saving user inputs + being able to retrieve it ThatOneGuyNoOneKnowsCodes 1 1,916 Oct-23-2019, 11:28 PM
Last Post: DT2000
  Define unit of measure of a number doug2019 3 2,379 Oct-15-2019, 03:43 PM
Last Post: jefsummers
  Unit testing - AssertRaises kerzol81 3 4,563 Oct-07-2019, 10:35 AM
Last Post: buran
  Trying to prompt user for 2 inputs on one line pythonprogrammer 2 2,497 Sep-15-2019, 04:41 PM
Last Post: snippsat
  user inputs in constructing a dictionary Exsul 3 3,698 Apr-10-2019, 12:25 PM
Last Post: ichabod801
  How to use a string method on user input Exsul 2 2,625 Mar-17-2019, 08:12 PM
Last Post: Exsul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020