pytest-dev / pytest-twisted

test twisted code with pytest
BSD 3-Clause "New" or "Revised" License
46 stars 24 forks source link

Tests fail on Python 3.10 due to deprecation of threading.currentThread() #146

Closed whitslack closed 3 years ago

whitslack commented 3 years ago

When running the tests on Python 3.10, I get failures because of an extra warning in the Pytest output:

/usr/lib/python3.10/site-packages/twisted/python/threadable.py:107: DeprecationWarning: currentThread() is deprecated, use current_thread() instead

The currentThread() function was deprecated in Python 3.10.

altendky commented 3 years ago

Wow... introduced in 2.6 even... Thanks for pointing this out.

https://docs.python.org/2.7/library/threading.html#threading.current_thread

But, that is in https://github.com/twisted/twisted itself, not pytest-twisted here. I'll go ahead and create a PR over there to keep things moving though and provide a link here in a few minutes.

altendky commented 3 years ago

https://twistedmatrix.com/trac/ticket/10273 https://github.com/twisted/twisted/pull/1671

bnavigator commented 2 years ago

For the record, as this has not found its way into Twisted yet: you can appease the python-twisted test suite by this patch:

Index: pytest-twisted-1.13.4/pytest.ini
===================================================================
--- pytest-twisted-1.13.4.orig/pytest.ini
+++ pytest-twisted-1.13.4/pytest.ini
@@ -1,3 +1,5 @@
 [pytest]
 addopts = --verbose
-filterwarnings = error
+filterwarnings =
+    error
+    ignore:currentThread:DeprecationWarning
Index: pytest-twisted-1.13.4/testing/test_basic.py
===================================================================
--- pytest-twisted-1.13.4.orig/testing/test_basic.py
+++ pytest-twisted-1.13.4/testing/test_basic.py
@@ -94,8 +94,13 @@ def skip_if_no_async_generators():

 @pytest.fixture
-def cmd_opts(request):
+def cmd_opts(request, testdir):
     reactor = request.config.getoption("reactor", "default")
+    pytest_ini_file = """
+    [pytest]
+    filterwarnings = ignore:currentThread:DeprecationWarning
+    """
+    testdir.makefile(".ini", pytest=pytest_ini_file)
     return (
         sys.executable,
         "-m",
@@ -370,6 +375,8 @@ def test_async_fixture(testdir, cmd_opts
     [pytest]
     markers =
         redgreenblue
+    filterwarnings =
+        ignore:currentThread:DeprecationWarning
     """
     testdir.makefile('.ini', pytest=pytest_ini_file)
     test_file = """
whitslack commented 2 years ago

you can appease the python-twisted test suite by this patch

Beautiful! The patch eliminates the test failure on Gentoo with Python 3.10. Thanks, @bnavigator.