Skip to content

Commit 830f8ed

Browse files
tests: update pytest 6.2.1 and fix test_python_alreadyset_in_destructor (#2741)
* Update pytest to 6.2.1 in tests/requirements.txt * Pin pytest to last supported version for 3.5 * Suppress PytestUnraisableExceptionWarning and use sys.__unraisablehook__ instead of sys.unraisablehook * Fix filterwarnings mark on old pytest and old Python versions * Cleanup ignore_pytest_unraisable_warning decorator
1 parent 6f66e76 commit 830f8ed

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

tests/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ numpy==1.16.6; python_version<"3.6" and sys_platform!="win32"
33
numpy==1.18.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version>="3.6"
44
numpy==1.19.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10"
55
pytest==4.6.9; python_version<"3.5"
6-
pytest==5.4.3; python_version>="3.5"
6+
pytest==6.1.2; python_version=="3.5"
7+
pytest==6.2.1; python_version>="3.6"
78
scipy==1.2.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version<"3.6"
89
scipy==1.5.2; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.9"

tests/test_exceptions.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,24 @@ def test_python_call_in_catch():
5050
assert d["good"] is True
5151

5252

53+
def ignore_pytest_unraisable_warning(f):
54+
unraisable = "PytestUnraisableExceptionWarning"
55+
if hasattr(pytest, unraisable): # Python >= 3.8 and pytest >= 6
56+
dec = pytest.mark.filterwarnings("ignore::pytest.{}".format(unraisable))
57+
return dec(f)
58+
else:
59+
return f
60+
61+
62+
@ignore_pytest_unraisable_warning
5363
def test_python_alreadyset_in_destructor(monkeypatch, capsys):
5464
hooked = False
5565
triggered = [False] # mutable, so Python 2.7 closure can modify it
5666

5767
if hasattr(sys, "unraisablehook"): # Python 3.8+
5868
hooked = True
59-
default_hook = sys.unraisablehook
69+
# Don't take `sys.unraisablehook`, as that's overwritten by pytest
70+
default_hook = sys.__unraisablehook__
6071

6172
def hook(unraisable_hook_args):
6273
exc_type, exc_value, exc_tb, err_msg, obj = unraisable_hook_args

0 commit comments

Comments
 (0)