[issue15351] Add to unittest.TestCase support for using context managers
Julian Berman
report at bugs.python.org
Sun Apr 7 03:25:12 CEST 2013
Julian Berman added the comment:
Now that we have contextlib.ExitStack, I think we should consider that here.
I.e., I think ExitStack deserves a method that calls its __enter__ and __exit__, say .enter() and .exit(), and then the idiom for this wouldn't require anything on TestCase, it'd be:
class TestStuff(TestCase):
def setUp(self):
self.stack = ExitStack()
self.stack.enter_context(my_context_manager())
self.stack.enter_context(my_context_manager2())
self.stack.enter_context(my_context_manager3())
self.stack.enter()
self.addCleanup(self.stack.exit)
----------
nosy: +Julian
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15351>
_______________________________________
More information about the Python-bugs-list
mailing list