diff options
author | Tom Gringauz <tomgrin10@gmail.com> | 2020-11-09 12:34:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-09 12:34:07 (GMT) |
commit | a117167d8dc8fa673a4646f509551c7950f824e5 (patch) | |
tree | 14ed56dc05c33931932c8e911a76b374d9fd74b1 /Lib/test | |
parent | 97e8b1eaeaf3aa325c84ff2e13417c30414d0269 (diff) | |
download | cpython-a117167d8dc8fa673a4646f509551c7950f824e5.zip cpython-a117167d8dc8fa673a4646f509551c7950f824e5.tar.gz cpython-a117167d8dc8fa673a4646f509551c7950f824e5.tar.bz2 |
bpo-41543: contextlib.nullcontext can fill in for an async context manager (GH-21870)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_contextlib_async.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_contextlib_async.py b/Lib/test/test_contextlib_async.py index 109807d..290ef05 100644 --- a/Lib/test/test_contextlib_async.py +++ b/Lib/test/test_contextlib_async.py @@ -1,5 +1,7 @@ import asyncio -from contextlib import aclosing, asynccontextmanager, AbstractAsyncContextManager, AsyncExitStack +from contextlib import ( + asynccontextmanager, AbstractAsyncContextManager, + AsyncExitStack, nullcontext, aclosing) import functools from test import support import unittest @@ -537,5 +539,15 @@ class TestAsyncExitStack(TestBaseExitStack, unittest.TestCase): self.assertIsInstance(inner_exc.__context__, ZeroDivisionError) +class TestAsyncNullcontext(unittest.TestCase): + @_async_test + async def test_async_nullcontext(self): + class C: + pass + c = C() + async with nullcontext(c) as c_in: + self.assertIs(c_in, c) + + if __name__ == '__main__': unittest.main() |