Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ class A:
def woohoo(a, b):
a = weakref.ref(a)
b = weakref.ref(b)
# Allow test to work with a non-refcounted GC
support.gc_collect()
self.assertIsNone(a())
self.assertIsNone(b())
yield
Expand Down
15 changes: 9 additions & 6 deletions Lib/test/test_contextlib_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from contextlib import (
asynccontextmanager, AbstractAsyncContextManager,
AsyncExitStack, nullcontext, aclosing)
AsyncExitStack, nullcontext, aclosing, contextmanager)
import functools
from test import support
import unittest
Expand Down Expand Up @@ -357,14 +357,17 @@ async def aclose(self):
async def test_aclosing_bpo41229(self):
state = []

class Resource:
def __del__(self):
@contextmanager
def sync_resource():
try:
yield
finally:
state.append(1)

async def agenfunc():
r = Resource()
yield -1
yield -2
with sync_resource():
yield -1
yield -2

x = agenfunc()
self.assertEqual(state, [])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Adjust recently added contextlib tests to avoid assuming the use of a
refcounted GC