Getting "NoneType object has no attribute" when using "with ... as" for custom context manager
<p>I wrote a simple context manager in Python for handling unit tests (and to try to learn context managers):</p>

<pre><code>class TestContext(object):
    test_count=1
    def __init__(self):
        self.test_number = TestContext.test_count
        TestContext.test_count += 1

    def __enter__(self):
        pass

    def __exit__(self, exc_type, exc_value, exc_traceback):
        if exc_value == None:
            print 'Test %d passed' %self.test_number
        else:
            print 'Test %d failed: %s' %(self.test_number, exc_value)
        return True
</code></pre>

<p>If I write a test as follows, everything works okay.</p>

<pre><code>test = TestContext()
with test:
   print 'running test %d....' %test.test_number
   raise Exception('this test failed')
</code></pre>

<p>However, if I try to use with...as, I don't get a reference to the TestContext() object.  Running this:</p>

<pre><code>with TestContext() as t:
    print t.test_number
</code></pre>

<p>Raises the exception <code>'NoneType' object has no attribute 'test_number'</code>.</p>

<p>Where am I going wrong?</p>