From 82d1a374575d9785708f144976cf139c76c7acb7 2022-01-03 10:46:40 From: Min RK Date: 2022-01-03 10:46:40 Subject: [PATCH] make sure to run async tests there are some `async def` tests, but they are skipped without `mark("asyncio")` --- diff --git a/IPython/conftest.py b/IPython/conftest.py index fb73d4b..abf6131 100644 --- a/IPython/conftest.py +++ b/IPython/conftest.py @@ -1,10 +1,12 @@ -import types -import sys import builtins +import inspect import os -import pytest import pathlib import shutil +import sys +import types + +import pytest # Must register before it gets imported pytest.register_assert_rewrite("IPython.testing.tools") @@ -12,6 +14,19 @@ pytest.register_assert_rewrite("IPython.testing.tools") from .testing import tools +def pytest_collection_modifyitems(items): + """This function is automatically run by pytest passing all collected test + functions. + + We use it to add asyncio marker to all async tests and assert we don't use + test functions that are async generators which wouldn't make sense. + """ + for item in items: + if inspect.iscoroutinefunction(item.obj): + item.add_marker("asyncio") + assert not inspect.isasyncgenfunction(item.obj) + + def get_ipython(): from .terminal.interactiveshell import TerminalInteractiveShell if TerminalInteractiveShell._instance: @@ -32,7 +47,7 @@ def work_path(): if path.exists(): raise ValueError('IPython dir temporary path already exists ! Did previous test run exit successfully ?') path.mkdir() - yield + yield shutil.rmtree(str(path.resolve())) diff --git a/setup.py b/setup.py index 3aa9be2..2ddebd6 100644 --- a/setup.py +++ b/setup.py @@ -150,6 +150,7 @@ extras_require = dict( doc=["Sphinx>=1.3"], test=[ "pytest", + "pytest-asyncio", "testpath", "pygments", ],