[issue15351] Add to unittest.TestCase support for using context managers

2021-08-29 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Opened issue45046 for completely different approach to this problem. -- nosy: +serhiy.storchaka ___ Python tracker ___

[issue15351] Add to unittest.TestCase support for using context managers

2014-03-20 Thread Martin Panter
Changes by Martin Panter : -- nosy: +vadmium ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

[issue15351] Add to unittest.TestCase support for using context managers

2013-04-06 Thread Julian Berman
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:

[issue15351] Add to unittest.TestCase support for using context managers

2013-04-02 Thread Chris Calloway
Changes by Chris Calloway : -- nosy: +cbc ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.or

[issue15351] Add to unittest.TestCase support for using context managers

2013-02-11 Thread Michael Foord
Changes by Michael Foord : -- assignee: -> michael.foord ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http:

[issue15351] Add to unittest.TestCase support for using context managers

2012-10-15 Thread Eli Bendersky
Changes by Eli Bendersky : -- nosy: +eli.bendersky ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.

[issue15351] Add to unittest.TestCase support for using context managers

2012-08-23 Thread Chris Jerdonek
Chris Jerdonek added the comment: Adding Éric because of the interest in test setup and tear down in issue 11664. -- nosy: +eric.araujo ___ Python tracker ___ ___

[issue15351] Add to unittest.TestCase support for using context managers

2012-07-16 Thread Chris Jerdonek
Chris Jerdonek added the comment: Attached is a patch illustrating the API I suggested for discussion. To add custom setup and teardown context managers, the user can override the following method: def executeTest(self): with self.setUpContext(): self.runTestMethod()

[issue15351] Add to unittest.TestCase support for using context managers

2012-07-15 Thread Michael Foord
Michael Foord added the comment: A method on TestCase that *just* executes the test method - allowing for overriding in subclasses - is an interesting idea. Including setUp and tearDown would be harder because TestCase necessarily does a bunch of bookkeeping between each of these steps.

[issue15351] Add to unittest.TestCase support for using context managers

2012-07-14 Thread Chris Jerdonek
Chris Jerdonek added the comment: Thanks for the interesting background and feedback. I was aware of the __enter__/__exit__ option but not the other information. And yes, I agree on the importance of trying and discussing any API before settling on it. The one I suggested was merely a point o

[issue15351] Add to unittest.TestCase support for using context managers

2012-07-14 Thread R. David Murray
R. David Murray added the comment: That should have been self.addCleanup(MyContextManager.__exit__) You could alternatively call __exit__() explicitly in tearDown, of course, but I believe addCleanup is a more reliable cleanup than tearDown. -- ___

[issue15351] Add to unittest.TestCase support for using context managers

2012-07-14 Thread R. David Murray
R. David Murray added the comment: Well, if you want to invoke the context in setup/teardown for some reason (as opposed to in the test methods themselves), you can do this: def setUp(self): self.foo = MyContextManager.__enter__() self.addCleanup(MyContextManager.__exit__()) Per

[issue15351] Add to unittest.TestCase support for using context managers

2012-07-14 Thread Chris Jerdonek
New submission from Chris Jerdonek : The setUp() and tearDown() methods of unittest.TestCase are of course extremely useful. But sometimes one has set up and tear down functionality that one would like to apply in the form of an existing context manager (and that may be from an outside source