diff options
author | Jesse-Bakker <jessebakker00@gmail.com> | 2017-11-23 00:23:28 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-11-23 00:23:28 (GMT) |
commit | 0784a2e5b174d2dbf7b144d480559e650c5cf64c (patch) | |
tree | 473d05eaf7ec712c9e6e023a0d43db3006a75981 /Lib/test/test_contextlib.py | |
parent | 20d48a44a54ed5e4a6df00e89ae27e3983128265 (diff) | |
download | cpython-0784a2e5b174d2dbf7b144d480559e650c5cf64c.zip cpython-0784a2e5b174d2dbf7b144d480559e650c5cf64c.tar.gz cpython-0784a2e5b174d2dbf7b144d480559e650c5cf64c.tar.bz2 |
bpo-10049: Add a "no-op" (null) context manager to contextlib (GH-4464)
Adds a simpler and faster alternative to ExitStack for handling
single optional context managers without having to change the
lexical structure of your code.
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r-- | Lib/test/test_contextlib.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index 64b6578..1a5e6ed 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -252,6 +252,16 @@ class ClosingTestCase(unittest.TestCase): 1 / 0 self.assertEqual(state, [1]) + +class NullcontextTestCase(unittest.TestCase): + def test_nullcontext(self): + class C: + pass + c = C() + with nullcontext(c) as c_in: + self.assertIs(c_in, c) + + class FileContextTestCase(unittest.TestCase): def testWithOpen(self): |