Skip to content

Commit f676782

Browse files
env: Add surrogate for pytest.deprecated_call for ptyest<3.9 (#2923)
env: Add surrogate for pytest.deprecated_call for ptyest<3.9
1 parent 1259db6 commit f676782

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

tests/env.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import platform
33
import sys
44

5+
import pytest
6+
57
LINUX = sys.platform.startswith("linux")
68
MACOS = sys.platform.startswith("darwin")
79
WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin")
@@ -12,3 +14,20 @@
1214
PY2 = sys.version_info.major == 2
1315

1416
PY = sys.version_info
17+
18+
19+
def deprecated_call():
20+
"""
21+
pytest.deprecated_call() seems broken in pytest<3.9.x; concretely, it
22+
doesn't work on CPython 3.8.0 with pytest==3.3.2 on Ubuntu 18.04 (#2922).
23+
24+
This is a narrowed reimplementation of the following PR :(
25+
https://github.com/pytest-dev/pytest/pull/4104
26+
"""
27+
# TODO: Remove this when testing requires pytest>=3.9.
28+
pieces = pytest.__version__.split(".")
29+
pytest_major_minor = (int(pieces[0]), int(pieces[1]))
30+
if pytest_major_minor < (3, 9):
31+
return pytest.warns((DeprecationWarning, PendingDeprecationWarning))
32+
else:
33+
return pytest.deprecated_call()

tests/test_builtin_casters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def cant_convert(v):
301301
cant_convert(3.14159)
302302
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
303303
if (3, 8) <= env.PY < (3, 10):
304-
with pytest.deprecated_call():
304+
with env.deprecated_call():
305305
assert convert(Int()) == 42
306306
else:
307307
assert convert(Int()) == 42
@@ -336,7 +336,7 @@ def require_implicit(v):
336336
# The implicit conversion from np.float32 is undesirable but currently accepted.
337337
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
338338
if (3, 8) <= env.PY < (3, 10):
339-
with pytest.deprecated_call():
339+
with env.deprecated_call():
340340
assert convert(np.float32(3.14159)) == 3
341341
else:
342342
assert convert(np.float32(3.14159)) == 3

0 commit comments

Comments
 (0)