From 615eeeaffe6469e3902fb6d91a30545c60af70ff Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Thu, 24 Dec 2020 00:07:26 +0100 Subject: [PATCH 1/5] Update pytest to 6.2.1 in tests/requirements.txt --- tests/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index 80ed6171d7..c6c84f0661 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -3,6 +3,6 @@ numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" numpy==1.18.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version>="3.6" numpy==1.19.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10" pytest==4.6.9; python_version<"3.5" -pytest==5.4.3; python_version>="3.5" +pytest==6.2.1; python_version>="3.5" scipy==1.2.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version<"3.6" scipy==1.5.2; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.9" From b456a8209378343813e8d628976a516422eb66df Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Thu, 24 Dec 2020 00:14:50 +0100 Subject: [PATCH 2/5] Pin pytest to last supported version for 3.5 --- tests/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index c6c84f0661..a6253e0042 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -3,6 +3,7 @@ numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" numpy==1.18.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version>="3.6" numpy==1.19.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10" pytest==4.6.9; python_version<"3.5" -pytest==6.2.1; python_version>="3.5" +pytest==6.1.2; python_version=="3.5" +pytest==6.2.1; python_version>="3.6" scipy==1.2.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version<"3.6" scipy==1.5.2; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.9" From 008be88402dc964cea5d35f438991634bab24fec Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Thu, 24 Dec 2020 00:47:34 +0100 Subject: [PATCH 3/5] Suppress PytestUnraisableExceptionWarning and use sys.__unraisablehook__ instead of sys.unraisablehook --- tests/test_exceptions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 95eac70928..f8ce27689d 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -50,13 +50,15 @@ def test_python_call_in_catch(): assert d["good"] is True +@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning") def test_python_alreadyset_in_destructor(monkeypatch, capsys): hooked = False triggered = [False] # mutable, so Python 2.7 closure can modify it if hasattr(sys, "unraisablehook"): # Python 3.8+ hooked = True - default_hook = sys.unraisablehook + # Don't take `sys.unraisablehook`, as that's overwritten by pytest + default_hook = sys.__unraisablehook__ def hook(unraisable_hook_args): exc_type, exc_value, exc_tb, err_msg, obj = unraisable_hook_args From df68528f69c6294068de3851bb3bbc55536e3f2a Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Thu, 24 Dec 2020 01:03:43 +0100 Subject: [PATCH 4/5] Fix filterwarnings mark on old pytest and old Python versions --- tests/test_exceptions.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index f8ce27689d..7c5f9ede71 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -50,7 +50,15 @@ def test_python_call_in_catch(): assert d["good"] is True -@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning") +if hasattr(pytest, "PytestUnraisableExceptionWarning"): # Python >= 3.8 and pytest >= 6 + ignore_pytest_unraisable_warning = pytest.mark.filterwarnings( + "ignore::pytest.PytestUnraisableExceptionWarning" + ) +else: + ignore_pytest_unraisable_warning = lambda f: f # NOQA: E731 + + +@ignore_pytest_unraisable_warning def test_python_alreadyset_in_destructor(monkeypatch, capsys): hooked = False triggered = [False] # mutable, so Python 2.7 closure can modify it From f21651a6025bc151606da48625f81b363d5d2e05 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Thu, 24 Dec 2020 02:38:30 +0100 Subject: [PATCH 5/5] Cleanup ignore_pytest_unraisable_warning decorator --- tests/test_exceptions.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 7c5f9ede71..c6cb65299e 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -50,12 +50,13 @@ def test_python_call_in_catch(): assert d["good"] is True -if hasattr(pytest, "PytestUnraisableExceptionWarning"): # Python >= 3.8 and pytest >= 6 - ignore_pytest_unraisable_warning = pytest.mark.filterwarnings( - "ignore::pytest.PytestUnraisableExceptionWarning" - ) -else: - ignore_pytest_unraisable_warning = lambda f: f # NOQA: E731 +def ignore_pytest_unraisable_warning(f): + unraisable = "PytestUnraisableExceptionWarning" + if hasattr(pytest, unraisable): # Python >= 3.8 and pytest >= 6 + dec = pytest.mark.filterwarnings("ignore::pytest.{}".format(unraisable)) + return dec(f) + else: + return f @ignore_pytest_unraisable_warning