title: How to write a generator class?
body: <p>I see lot of examples of generator functions, but I want to know how to write generators for classes. Lets say, I wanted to write Fibonacci series as a class. </p>
  
  <pre><code>class Fib:
      def __init__(self):
          self.a, self.b = 0, 1
  
      def __next__(self):
          yield self.a
          self.a, self.b = self.b, self.a+self.b
  
  f = Fib()
  
  for i in range(3):
      print(next(f))
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>&lt;generator object __next__ at 0x000000000A3E4F68&gt;
  &lt;generator object __next__ at 0x000000000A3E4F68&gt;
  &lt;generator object __next__ at 0x000000000A3E4F68&gt;
  </code></pre>
  
  <p>Why is the value <code>self.a</code> not getting printed?  Also, how do I write <code>unittest</code> for generators?   </p>