mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +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
|
@ -11,14 +11,10 @@ sentinel = object()
|
|||
|
||||
class GetoptTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.env = EnvironmentVarGuard()
|
||||
self.env = self.enterContext(EnvironmentVarGuard())
|
||||
if "POSIXLY_CORRECT" in self.env:
|
||||
del self.env["POSIXLY_CORRECT"]
|
||||
|
||||
def tearDown(self):
|
||||
self.env.__exit__()
|
||||
del self.env
|
||||
|
||||
def assertError(self, *args, **kwargs):
|
||||
self.assertRaises(getopt.GetoptError, *args, **kwargs)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue