mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-45046: Support context managers in unittest (GH-28045)
Add methods enterContext() and enterClassContext() in TestCase. Add method enterAsyncContext() in IsolatedAsyncioTestCase. Add function enterModuleContext().
This commit is contained in:
parent
8f29318079
commit
086c6b1b0f
26 changed files with 307 additions and 92 deletions
|
@ -41,9 +41,8 @@ class TestCase(unittest.TestCase):
|
|||
# The tests assume that line wrapping occurs at 80 columns, but this
|
||||
# behaviour can be overridden by setting the COLUMNS environment
|
||||
# variable. To ensure that this width is used, set COLUMNS to 80.
|
||||
env = os_helper.EnvironmentVarGuard()
|
||||
env = self.enterContext(os_helper.EnvironmentVarGuard())
|
||||
env['COLUMNS'] = '80'
|
||||
self.addCleanup(env.__exit__)
|
||||
|
||||
|
||||
class TempDirMixin(object):
|
||||
|
@ -3428,9 +3427,8 @@ class TestShortColumns(HelpTestCase):
|
|||
but we don't want any exceptions thrown in such cases. Only ugly representation.
|
||||
'''
|
||||
def setUp(self):
|
||||
env = os_helper.EnvironmentVarGuard()
|
||||
env = self.enterContext(os_helper.EnvironmentVarGuard())
|
||||
env.set("COLUMNS", '15')
|
||||
self.addCleanup(env.__exit__)
|
||||
|
||||
parser_signature = TestHelpBiggerOptionals.parser_signature
|
||||
argument_signatures = TestHelpBiggerOptionals.argument_signatures
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue