Let's say I have a method that looks like this:
def my_function(arg1, arg2):
if arg1:
raise RuntimeError('error message A')
else:
raise RuntimeError('error message B')
Using python's builtin unittets library, is there any way to tell WHICH RuntimeError
was raised? I have been doing:
import unittest
from myfile import my_function
class MyTestCase(unittest.TestCase):
def test_my_function(self):
self.assertRaises(RuntimeError, my_function, arg1, arg2)
But this only asserts that a RuntimeError
was encountered. I want to be able to tell WHICH RuntimeError
was encountered. Checking the actual error message is the only way I think this could be accomplished but I can't seem to find any assert method that also tries to assert the error message