Skip to content

Commit

Permalink
Fix test incompatibility with PyPy3
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoghlan committed Jun 26, 2021
1 parent 4b39470 commit 032662d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include *.py *.txt *.rst *.md *.ini MANIFEST.in
recursive-include test docs *.rst *.py make.bat Makefile
recursive-include dev test docs *.rst *.py make.bat Makefile
3 changes: 3 additions & 0 deletions test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from test import support
from test.support import os_helper
import weakref
import gc


class TestAbstractContextManager(unittest.TestCase):
Expand Down Expand Up @@ -228,6 +229,8 @@ class A:
def woohoo(a, b):
a = weakref.ref(a)
b = weakref.ref(b)
# Allow test to work with a non-refcounted GC
gc.collect(); gc.collect(); gc.collect()
self.assertIsNone(a())
self.assertIsNone(b())
yield
Expand Down
15 changes: 9 additions & 6 deletions test/test_contextlib_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from contextlib2 import (
asynccontextmanager, AbstractAsyncContextManager,
AsyncExitStack, nullcontext, aclosing)
AsyncExitStack, nullcontext, aclosing, contextmanager)
import functools
from test import support
import unittest
Expand Down Expand Up @@ -346,14 +346,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

0 comments on commit 032662d

Please sign in to comment.