|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 1, |
| 5 | + "execution_count": 3, |
6 | 6 | "id": "dde59e44-56d2-43cb-a9c7-dc5a07d96d1f",
|
7 | 7 | "metadata": {},
|
8 | 8 | "outputs": [],
|
|
13 | 13 | "def test_number_input():\n",
|
14 | 14 | " \"\"\"Tests number input with mocked input.\"\"\"\n",
|
15 | 15 | " with patch('builtins.input', side_effect=['10', '5']):\n",
|
16 |
| - " first_number = input('Enter your first number :')\n", |
17 |
| - " second_number = input('Enter your second number :')\n", |
| 16 | + " first_number = patch.return_value \n", |
| 17 | + " second_number = patch.return_value \n", |
18 | 18 | " sum_of_num = int(first_number) + int(second_number)\n",
|
19 | 19 | " assert sum_of_num == 15\n",
|
20 | 20 | "\n",
|
21 | 21 | "def test_number_input_second_way():\n",
|
22 | 22 | " \"\"\"Tests number input with mocked input (second way).\"\"\"\n",
|
23 |
| - " with patch('builtins.input', side_effect=['10', '5']):\n", |
24 |
| - " first_number = int(input('Enter your first number :'))\n", |
25 |
| - " second_number = int(input('Enter your second number :'))\n", |
| 23 | + " with patch('builtins.input', side_effect=['10', '5']) as mock_input:\n", |
| 24 | + " first_number = int(mock_input())\n", |
| 25 | + " second_number = int(mock_input())\n", |
26 | 26 | " sum_of_num = first_number + second_number\n",
|
27 | 27 | " assert sum_of_num == 15"
|
28 | 28 | ]
|
|
0 commit comments