Repository: ipython/ipython

Issue:
Using autoreload magic fails with the latest version
<!-- This is the repository for IPython command line, if you can try to make sure this question/bug/feature belong here and not on one of the Jupyter repositories. 

If it's a generic Python/Jupyter question, try other forums or discourse.jupyter.org.

If you are unsure, it's ok to post here, though, there are few maintainer so you might not get a fast response. 

-->
* Create a notebook with two cells
* First cell with the following code
```
%load_ext autoreload
%autoreload 2
```
* Second cell with
```
print(1234)
```

Upon running the second cell, the following error is displayed
```
Error in callback <bound method AutoreloadMagics.pre_run_cell of <IPython.extensions.autoreload.AutoreloadMagics object at 0x106796e90>> (for pre_run_cell):
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: AutoreloadMagics.pre_run_cell() takes 1 positional argument but 2 were given
```

Downgrading to 8.16.1 fixes this

Discussion:

Patch:
diff --git a/IPython/core/events.py b/IPython/core/events.py
index 90ff8f746..ef39c4fd0 100644
--- a/IPython/core/events.py
+++ b/IPython/core/events.py
@@ -82,7 +82,11 @@ def trigger(self, event, *args, **kwargs):
                 func(*args, **kwargs)
             except (Exception, KeyboardInterrupt):
                 if self.print_on_error:
-                    print("Error in callback {} (for {}):".format(func, event))
+                    print(
+                        "Error in callback {} (for {}), with arguments args {},kwargs {}:".format(
+                            func, event, args, kwargs
+                        )
+                    )
                 self.shell.showtraceback()
 
 # event_name -> prototype mapping
diff --git a/IPython/extensions/autoreload.py b/IPython/extensions/autoreload.py
index 0025ad519..98c9a0d01 100644
--- a/IPython/extensions/autoreload.py
+++ b/IPython/extensions/autoreload.py
@@ -701,7 +701,7 @@ def aimport(self, parameter_s="", stream=None):
                     # Inject module to user namespace
                     self.shell.push({top_name: top_module})
 
-    def pre_run_cell(self):
+    def pre_run_cell(self, info):
         if self._reloader.enabled:
             try:
                 self._reloader.check()
diff --git a/setup.cfg b/setup.cfg
index 65e6ed684..2dd5c6e97 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -73,7 +73,7 @@ qtconsole =
 terminal =
 test =
     pytest<7.1
-    pytest-asyncio
+    pytest-asyncio<0.22
     testpath
     pickleshare
 test_extra =


Test patch:
diff --git a/IPython/extensions/tests/test_autoreload.py b/IPython/extensions/tests/test_autoreload.py
index 89a4add32..781885dd9 100644
--- a/IPython/extensions/tests/test_autoreload.py
+++ b/IPython/extensions/tests/test_autoreload.py
@@ -21,6 +21,7 @@
 import shutil
 import random
 import time
+import traceback
 from io import StringIO
 from dataclasses import dataclass
 
@@ -31,6 +32,7 @@
 from IPython.extensions.autoreload import AutoreloadMagics
 from IPython.core.events import EventManager, pre_run_cell
 from IPython.testing.decorators import skipif_not_numpy
+from IPython.core.interactiveshell import ExecutionInfo
 
 if platform.python_implementation() == "PyPy":
     pytest.skip(
@@ -56,8 +58,27 @@ def __init__(self):
 
     register_magics = set_hook = noop
 
+    def showtraceback(
+        self,
+        exc_tuple=None,
+        filename=None,
+        tb_offset=None,
+        exception_only=False,
+        running_compiled_code=False,
+    ):
+        traceback.print_exc()
+
     def run_code(self, code):
-        self.events.trigger("pre_run_cell")
+        self.events.trigger(
+            "pre_run_cell",
+            ExecutionInfo(
+                raw_cell="",
+                store_history=False,
+                silent=False,
+                shell_futures=False,
+                cell_id=None,
+            ),
+        )
         exec(code, self.user_ns)
         self.auto_magics.post_execute_hook()
 
@@ -279,6 +300,7 @@ def power(self, p):
     @skipif_not_numpy
     def test_comparing_numpy_structures(self):
         self.shell.magic_autoreload("2")
+        self.shell.run_code("1+1")
         mod_name, mod_fn = self.new_module(
             textwrap.dedent(
                 """