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
|
@ -9,14 +9,9 @@ import warnings
|
|||
class GlobalTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._warnings_manager = check_warnings()
|
||||
self._warnings_manager.__enter__()
|
||||
self.enterContext(check_warnings())
|
||||
warnings.filterwarnings("error", module="<test string>")
|
||||
|
||||
def tearDown(self):
|
||||
self._warnings_manager.__exit__(None, None, None)
|
||||
|
||||
|
||||
def test1(self):
|
||||
prog_text_1 = """\
|
||||
def wrong1():
|
||||
|
@ -54,9 +49,7 @@ x = 2
|
|||
|
||||
|
||||
def setUpModule():
|
||||
cm = warnings.catch_warnings()
|
||||
cm.__enter__()
|
||||
unittest.addModuleCleanup(cm.__exit__, None, None, None)
|
||||
unittest.enterModuleContext(warnings.catch_warnings())
|
||||
warnings.filterwarnings("error", module="<test string>")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue