Repository: ipython/ipykernel (language: python)

Issue:
Compatibility with pytest 8
According to: https://docs.pytest.org/en/latest/deprecations.html#id14 pytest 8 no longer supports setup/teardown functions/methods which leads to many failures like this:

```
____________________________ test_asyncio_interrupt ____________________________

    @pytest.mark.skipif(tornado.version_info < (5,), reason="only relevant on tornado 5")
    def test_asyncio_interrupt():
>       assert KM is not None
E       assert None is not None

ipykernel/tests/test_eventloop.py:67: AssertionError
```

Because these functions are ignored: https://github.com/ipython/ipykernel/blob/5534fd99b7c0a936392b35ad20bee026790332bd/tests/test_eventloop.py#L45-L56


Discussion / hints:

Fix patch:
diff --git a/pyproject.toml b/pyproject.toml
index 909308af..cdf265f6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -54,7 +54,7 @@ docs = [
   "trio"
 ]
 test = [
-    "pytest>=7.0,<8",
+    "pytest>=7.0,<9",
     "pytest-cov",
     "flaky",
     "ipyparallel",


Test patch:
diff --git a/tests/__init__.py b/tests/__init__.py
index 013114bd..ee324a6f 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -7,6 +7,8 @@
 import tempfile
 from unittest.mock import patch
 
+import pytest
+
 from ipykernel.kernelspec import install
 
 pjoin = os.path.join
@@ -15,7 +17,8 @@
 patchers: list = []
 
 
-def setup():
+@pytest.fixture(autouse=True)
+def _global_setup():
     """setup temporary env for tests"""
     global tmp
     tmp = tempfile.mkdtemp()
@@ -34,9 +37,7 @@ def setup():
 
     # install IPython in the temp home:
     install(user=True)
-
-
-def teardown():
+    yield
     for p in patchers:
         p.stop()
 
diff --git a/tests/test_async.py b/tests/test_async.py
index 42267329..a40db4a0 100644
--- a/tests/test_async.py
+++ b/tests/test_async.py
@@ -11,14 +11,13 @@
 KC = KM = None
 
 
-def setup_function():
+@pytest.fixture(autouse=True)
+def _setup_env():
     """start the global kernel (if it isn't running) and return its client"""
     global KM, KC
     KM, KC = start_new_kernel()
     flush_channels(KC)
-
-
-def teardown_function():
+    yield
     assert KC is not None
     assert KM is not None
     KC.stop_channels()
diff --git a/tests/test_eventloop.py b/tests/test_eventloop.py
index 34581b7f..77596eed 100644
--- a/tests/test_eventloop.py
+++ b/tests/test_eventloop.py
@@ -42,14 +42,13 @@ def _get_qt_vers():
 _get_qt_vers()
 
 
-def setup():
+@pytest.fixture(autouse=True)
+def _setup_env():
     """start the global kernel (if it isn't running) and return its client"""
     global KM, KC
     KM, KC = start_new_kernel()
     flush_channels(KC)
-
-
-def teardown():
+    yield
     assert KM is not None
     assert KC is not None
     KC.stop_channels()
diff --git a/tests/test_message_spec.py b/tests/test_message_spec.py
index d9d8bb81..d98503ee 100644
--- a/tests/test_message_spec.py
+++ b/tests/test_message_spec.py
@@ -22,7 +22,8 @@
 KC: BlockingKernelClient = None  # type:ignore
 
 
-def setup():
+@pytest.fixture(autouse=True)
+def _setup_env():
     global KC
     KC = start_global_kernel()