Title: Test For A Specific Exception
Slug: test_for_a_specific_exception
Summary: Using Python.
Date: 2017-02-02 12:00
Category: Python
Tags: Testing
Authors: Chris Albon
In [1]:
import unittest
In [2]:
def add(x, y):
return x + y
In [3]:
# Create a test case
class TestAdd(unittest.TestCase):
# Create the unit test
def test_input_string(self):
# Test To make sure a TypeError exception is raised
self.assertRaises(TypeError, add('Banana', 'Boat'))
In [4]:
# Run the unit test (and don't shut down the Jupyter Notebook)
unittest.main(argv=['ignored', '-v'], exit=False)
Out[4]: