Skip to content

Instantly share code, notes, and snippets.

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