MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _apply_maybe_async

Function _apply_maybe_async

lib/sqlalchemy/testing/plugin/pytestplugin.py:373–402  ·  view source on GitHub ↗
(obj, recurse=True)

Source from the content-addressed store, hash-verified

371
372
373def _apply_maybe_async(obj, recurse=True):
374 from sqlalchemy.testing import asyncio
375
376 for name, value in vars(obj).items():
377 if (
378 (callable(value) or isinstance(value, classmethod))
379 and not getattr(value, "_maybe_async_applied", False)
380 and (name.startswith("test_"))
381 and not _is_wrapped_coroutine_function(value)
382 ):
383 is_classmethod = False
384 if isinstance(value, classmethod):
385 value = value.__func__
386 is_classmethod = True
387
388 @_pytest_fn_decorator
389 def make_async(fn, *args, **kwargs):
390 return asyncio._maybe_async(fn, *args, **kwargs)
391
392 do_async = make_async(value)
393 if is_classmethod:
394 do_async = classmethod(do_async)
395 do_async._maybe_async_applied = True
396
397 setattr(obj, name, do_async)
398 if recurse:
399 for cls in obj.mro()[1:]:
400 if cls != object:
401 _apply_maybe_async(cls, False)
402 return obj
403
404
405def _parametrize_cls(module, cls):

Callers 1

Calls 4

make_asyncFunction · 0.85
itemsMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected