From 032662d6e9fb7725712004d6f5d62c289d08d1a5 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Sat, 26 Jun 2021 18:30:55 +1000 Subject: [PATCH] Fix test incompatibility with PyPy3 --- MANIFEST.in | 2 +- test/test_contextlib.py | 3 +++ test/test_contextlib_async.py | 15 +++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 899523c..5b839f9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/test/test_contextlib.py b/test/test_contextlib.py index 8a9176b..f09090a 100644 --- a/test/test_contextlib.py +++ b/test/test_contextlib.py @@ -9,6 +9,7 @@ from test import support from test.support import os_helper import weakref +import gc class TestAbstractContextManager(unittest.TestCase): @@ -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 diff --git a/test/test_contextlib_async.py b/test/test_contextlib_async.py index c131724..eb2ed72 100644 --- a/test/test_contextlib_async.py +++ b/test/test_contextlib_async.py @@ -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 @@ -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, [])