Created
March 28, 2021 00:20
-
-
Save simon-saliba/77f34c3ad8f8731df929dffe3f31c12c to your computer and use it in GitHub Desktop.
Writing Mock Test for logging info to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from unittest.mock import patch | |
from stringcalculator import add | |
class TestStringCalculator(unittest.TestCase): | |
def test_add_empty_string_return_zero(self): | |
self.assertEqual(add(''), 0) | |
def test_add_one_number_will_return_itself(self): | |
self.assertEqual(add('2'), 2) | |
self.assertEqual(add('24'), 24) | |
def test_add_two_numbers_separated_by_comma(self): | |
self.assertEqual(add('1,2'),3) | |
self.assertEqual(add('21,9'),30) | |
@patch('stringcalculator.logging') | |
def test_add_result_logs_info(self, mock_logging): | |
add('1,2') | |
self.assertTrue(mock_logging.info.called) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment