class testExample(unittest.TestCase):

    def test_generatorExample(self):
        with self.assertRaises(RuntimeError):
            list(Example().generatorExample())
How to use unittest's self.assertRaises with exceptions in a generator object?