For this lab you will use unit testing to check a null setting using assertions. Use the commented template code provided to do the following:

For example, the output to the console from the source code multiply_numbers(5, None) will be the following output:

<aside> 💡 y is a null value 5 is not None

</aside>

# unit test case
import unittest

def multiply_numbers(x, y):
    #add your code here
    return x * y
   # add your code here
   
   
class TestForNone(unittest.TestCase):
        
    def test_when_a_is_null(self):
        try:
            self.assertIsNone(multiply_numbers(5, None))
        except AssertionError as msg:
            print(msg)

if __name__ == '__main__':  
    unittest.main()

Answer


# unit test case
import unittest

def multiply_numbers(x, y):
    #add your code here
    if x is None:
        print("x is a null value")
        return y
    elif y is None:
        print("y is a null value")
        return x
    else:
        return x * y   
   
   
class TestForNone(unittest.TestCase):
        
    def test_when_a_is_null(self):
        try:
            self.assertIsNone(multiply_numbers(5, None))
        except AssertionError as msg:
            print(msg)

if __name__ == '__main__':  
    unittest.main()