diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-02 10:55:21 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-02 19:08:25 -0500 |
commit | 5ba427f6daad4e7224267d11f7c6d99bd68f3d0e (patch) | |
tree | a6c7c112c0eb078521b0281c804578a63aa3810f /lib/sqlalchemy/testing/plugin/pytestplugin.py | |
parent | 2581655c545a0cf705e0347e81cd092896d3207c (diff) | |
download | sqlalchemy-5ba427f6daad4e7224267d11f7c6d99bd68f3d0e.tar.gz |
Repair async test refactor
in I4940d184a4dc790782fcddfb9873af3cca844398 we reworked how async
tests run but apparently the async tests in test/ext/asyncio
are reporting success without being run. This patch pushes
pytestplugin further so that it won't instrument any test
or function overall that declares itself async. This removes
the need for the __async_wrap__ flag and also allows us to
use a more strict "run_async_test" function that always
runs the asyncio event loop from the top.
Also start working asyncio into main testing suite.
Change-Id: If7144e951a9db67eb7ea73b377f81c4440d39819
Diffstat (limited to 'lib/sqlalchemy/testing/plugin/pytestplugin.py')
-rw-r--r-- | lib/sqlalchemy/testing/plugin/pytestplugin.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py index 6be64aa61..46468a07d 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -255,7 +255,7 @@ def pytest_pycollect_makeitem(collector, name, obj): if inspect.isclass(obj) and plugin_base.want_class(name, obj): from sqlalchemy.testing import config - if config.any_async and getattr(obj, "__asyncio_wrap__", True): + if config.any_async: obj = _apply_maybe_async(obj) ctor = getattr(pytest.Class, "from_parent", pytest.Class) @@ -277,6 +277,13 @@ def pytest_pycollect_makeitem(collector, name, obj): return [] +def _is_wrapped_coroutine_function(fn): + while hasattr(fn, "__wrapped__"): + fn = fn.__wrapped__ + + return inspect.iscoroutinefunction(fn) + + def _apply_maybe_async(obj, recurse=True): from sqlalchemy.testing import asyncio @@ -286,6 +293,7 @@ def _apply_maybe_async(obj, recurse=True): (callable(value) or isinstance(value, classmethod)) and not getattr(value, "_maybe_async_applied", False) and (name.startswith("test_") or name in setup_names) + and not _is_wrapped_coroutine_function(value) ): is_classmethod = False if isinstance(value, classmethod): @@ -656,6 +664,6 @@ class PytestFixtureFunctions(plugin_base.FixtureFunctions): @_pytest_fn_decorator def decorate(fn, *args, **kwargs): - asyncio._assume_async(fn, *args, **kwargs) + asyncio._run_coroutine_function(fn, *args, **kwargs) return decorate(fn) |