title: How to use unittest's self.assertRaises with exceptions in a generator object?
body: <p>I got a generator object that I want to unittest. It goes through a loop and, when at the end of the loop a certain variable is still 0 I raise an exception. I want to unittest this, but I don't know how. 
  Take this example generator:</p>
  
  <pre><code>class Example():
      def generatorExample(self):
          count = 0
          for int in range(1,100):
              count += 1
              yield count   
          if count &gt; 0:
               raise RuntimeError, 'an example error that will always happen'
  </code></pre>
  
  <p>What I would like to do is</p>
  
  <pre><code>class testExample(unittest.TestCase):
      def test_generatorExample(self):
          self.assertRaises(RuntimeError, Example.generatorExample)
  </code></pre>
  
  <p>However, a generator object isn't calable and this gives </p>
  
  <pre><code>TypeError: 'generator' object is not callable
  </code></pre>
  
  <p>So how do you test if an exception is raised in a generator function?</p>