diff --git a/examples/pyo3-pytests/tests/test_objstore.py b/examples/pyo3-pytests/tests/test_objstore.py index 99713948..0b1f46f4 100644 --- a/examples/pyo3-pytests/tests/test_objstore.py +++ b/examples/pyo3-pytests/tests/test_objstore.py @@ -3,22 +3,23 @@ import platform import sys import pytest - from pyo3_pytests.objstore import ObjStore -PYPY = platform.python_implementation() == "PyPy" - -@pytest.mark.skipif(PYPY, reason="PyPy does not have sys.getrefcount") def test_objstore_doesnot_leak_memory(): N = 10000 message = b'\\(-"-;) Praying that memory leak would not happen..' - before = sys.getrefcount(message) + + # PyPy does not have sys.getrefcount, provide a no-op lambda and don't + # check refcount on PyPy + getrefcount = getattr(sys, "getrefcount", lambda obj: 0) + + before = getrefcount(message) store = ObjStore() for _ in range(N): store.push(message) del store gc.collect() - after = sys.getrefcount(message) + after = getrefcount(message) assert after - before == 0 diff --git a/examples/pyo3-pytests/tests/test_subclassing.py b/examples/pyo3-pytests/tests/test_subclassing.py index e1c0b88f..5851c033 100644 --- a/examples/pyo3-pytests/tests/test_subclassing.py +++ b/examples/pyo3-pytests/tests/test_subclassing.py @@ -2,8 +2,6 @@ import platform from pyo3_pytests.subclassing import Subclassable -PYPY = platform.python_implementation() == "PyPy" - class SomeSubClass(Subclassable): def __str__(self): @@ -11,7 +9,6 @@ class SomeSubClass(Subclassable): def test_subclassing(): - if not PYPY: - a = SomeSubClass() - assert str(a) == "SomeSubclass" - assert type(a) is SomeSubClass + a = SomeSubClass() + assert str(a) == "SomeSubclass" + assert type(a) is SomeSubClass