Skip to content

Instantly share code, notes, and snippets.

@njgibbon
Last active July 23, 2021 18:45
Show Gist options
  • Save njgibbon/d6c1498b88d3122e7a55b2e008c31423 to your computer and use it in GitHub Desktop.
Save njgibbon/d6c1498b88d3122e7a55b2e008c31423 to your computer and use it in GitHub Desktop.
test_divide_good.py
import unittest
import divide
class TestDivide(unittest.TestCase):
def test_divide_pass_0(self):
self.assertEqual(divide.divide(10, 5), 2)
def test_divide_pass_1(self):
self.assertEqual(divide.divide(100, 10), 10)
def test_divide_unexpected_fail(self):
"""
We know this will throw a Runtime Error. But imagine we didn't.
"""
self.assertEqual(divide.divide(10, 0), 3)
def test_divide_expected_fail(self):
"""Correct way to test error scenarios"""
self.assertRaises(ZeroDivisionError, divide.divide, 8, 0)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment