tests: cleanup and ci hardening (#2397)
* tests: refactor and cleanup
* refactor: more consistent
* tests: vendor six
* tests: more xfails, nicer system
* tests: simplify to info
* tests: suggestions from @YannickJadoul and @bstaletic
* tests: restore some pypy tests that now pass
* tests: rename info to env
* tests: strict False/True
* tests: drop explicit strict=True again
* tests: reduce minimum PyTest to 3.1
diff --git a/tests/test_buffers.py b/tests/test_buffers.py
index db1871e..d6adaf1 100644
--- a/tests/test_buffers.py
+++ b/tests/test_buffers.py
@@ -4,13 +4,12 @@
import pytest
+import env # noqa: F401
+
from pybind11_tests import buffers as m
from pybind11_tests import ConstructorStats
-pytestmark = pytest.requires_numpy
-
-with pytest.suppress(ImportError):
- import numpy as np
+np = pytest.importorskip("numpy")
def test_from_python():
@@ -36,9 +35,7 @@
assert cstats.move_assignments == 0
-# PyPy: Memory leak in the "np.array(m, copy=False)" call
-# https://bitbucket.org/pypy/pypy/issues/2444
-@pytest.unsupported_on_pypy
+# https://foss.heptapod.net/pypy/pypy/-/issues/2444
def test_to_python():
mat = m.Matrix(5, 4)
assert memoryview(mat).shape == (5, 4)
@@ -73,7 +70,6 @@
assert cstats.move_assignments == 0
-@pytest.unsupported_on_pypy
def test_inherited_protocol():
"""SquareMatrix is derived from Matrix and inherits the buffer protocol"""
@@ -82,7 +78,6 @@
assert np.asarray(matrix).shape == (5, 5)
-@pytest.unsupported_on_pypy
def test_pointer_to_member_fn():
for cls in [m.Buffer, m.ConstBuffer, m.DerivedBuffer]:
buf = cls()
@@ -91,19 +86,17 @@
assert value == 0x12345678
-@pytest.unsupported_on_pypy
def test_readonly_buffer():
buf = m.BufferReadOnly(0x64)
view = memoryview(buf)
- assert view[0] == b'd' if pytest.PY2 else 0x64
+ assert view[0] == b'd' if env.PY2 else 0x64
assert view.readonly
-@pytest.unsupported_on_pypy
def test_selective_readonly_buffer():
buf = m.BufferReadOnlySelect()
- memoryview(buf)[0] = b'd' if pytest.PY2 else 0x64
+ memoryview(buf)[0] = b'd' if env.PY2 else 0x64
assert buf.value == 0x64
io.BytesIO(b'A').readinto(buf)
@@ -111,6 +104,6 @@
buf.readonly = True
with pytest.raises(TypeError):
- memoryview(buf)[0] = b'\0' if pytest.PY2 else 0
+ memoryview(buf)[0] = b'\0' if env.PY2 else 0
with pytest.raises(TypeError):
io.BytesIO(b'1').readinto(buf)