mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
env: Add surrogate for pytest.deprecated_call for ptyest<3.9 (#2923)
env: Add surrogate for pytest.deprecated_call for ptyest<3.9
This commit is contained in:
parent
1259db6fd9
commit
f676782bec
19
tests/env.py
19
tests/env.py
@ -2,6 +2,8 @@
|
|||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
LINUX = sys.platform.startswith("linux")
|
LINUX = sys.platform.startswith("linux")
|
||||||
MACOS = sys.platform.startswith("darwin")
|
MACOS = sys.platform.startswith("darwin")
|
||||||
WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin")
|
WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin")
|
||||||
@ -12,3 +14,20 @@ PYPY = platform.python_implementation() == "PyPy"
|
|||||||
PY2 = sys.version_info.major == 2
|
PY2 = sys.version_info.major == 2
|
||||||
|
|
||||||
PY = sys.version_info
|
PY = sys.version_info
|
||||||
|
|
||||||
|
|
||||||
|
def deprecated_call():
|
||||||
|
"""
|
||||||
|
pytest.deprecated_call() seems broken in pytest<3.9.x; concretely, it
|
||||||
|
doesn't work on CPython 3.8.0 with pytest==3.3.2 on Ubuntu 18.04 (#2922).
|
||||||
|
|
||||||
|
This is a narrowed reimplementation of the following PR :(
|
||||||
|
https://github.com/pytest-dev/pytest/pull/4104
|
||||||
|
"""
|
||||||
|
# TODO: Remove this when testing requires pytest>=3.9.
|
||||||
|
pieces = pytest.__version__.split(".")
|
||||||
|
pytest_major_minor = (int(pieces[0]), int(pieces[1]))
|
||||||
|
if pytest_major_minor < (3, 9):
|
||||||
|
return pytest.warns((DeprecationWarning, PendingDeprecationWarning))
|
||||||
|
else:
|
||||||
|
return pytest.deprecated_call()
|
||||||
|
@ -301,7 +301,7 @@ def test_int_convert():
|
|||||||
cant_convert(3.14159)
|
cant_convert(3.14159)
|
||||||
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
|
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
|
||||||
if (3, 8) <= env.PY < (3, 10):
|
if (3, 8) <= env.PY < (3, 10):
|
||||||
with pytest.deprecated_call():
|
with env.deprecated_call():
|
||||||
assert convert(Int()) == 42
|
assert convert(Int()) == 42
|
||||||
else:
|
else:
|
||||||
assert convert(Int()) == 42
|
assert convert(Int()) == 42
|
||||||
@ -336,7 +336,7 @@ def test_numpy_int_convert():
|
|||||||
# The implicit conversion from np.float32 is undesirable but currently accepted.
|
# The implicit conversion from np.float32 is undesirable but currently accepted.
|
||||||
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
|
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
|
||||||
if (3, 8) <= env.PY < (3, 10):
|
if (3, 8) <= env.PY < (3, 10):
|
||||||
with pytest.deprecated_call():
|
with env.deprecated_call():
|
||||||
assert convert(np.float32(3.14159)) == 3
|
assert convert(np.float32(3.14159)) == 3
|
||||||
else:
|
else:
|
||||||
assert convert(np.float32(3.14159)) == 3
|
assert convert(np.float32(3.14159)) == 3
|
||||||
|
Loading…
Reference in New Issue
Block a user