Message 131838 - Python tracker (original) (raw)

If you add the following test to text_contextlib:

diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -363,6 +363,8 @@ class TestContextDecorator(unittest.Test state.append(x) test('something') self.assertEqual(state, [1, 'something', 999])

This is needed to make the test actually run under regrtest.py!

You get the following error:

====================================================================== ERROR: test_contextmanager_as_decorator (test.test_contextlib.TestContextDecorator)

Traceback (most recent call last): File "/home/antoine/cpython/32/Lib/contextlib.py", line 28, in enter return next(self.gen) StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/antoine/cpython/32/Lib/test/test_contextlib.py", line 366, in test_contextmanager_as_decorator test('something else') File "/home/antoine/cpython/32/Lib/contextlib.py", line 15, in inner with self: File "/home/antoine/cpython/32/Lib/contextlib.py", line 30, in enter raise RuntimeError("generator didn't yield") RuntimeError: generator didn't yield

Clearly there is a problem in the API or its implementation, as in a function decorated with a context manager can only be invoked once! This isn't good...