def pytest_pycollect_makeitem(collector, name, obj):

    if inspect.isclass(obj) and plugin_base.want_class(name, obj):

        # in pytest 5.4.0
        # return [
        #     pytest.Class.from_parent(collector,
        # name=parametrize_cls.__name__)
        #     for parametrize_cls in _parametrize_cls(collector.module, obj)
        # ]

        return [
            pytest.Class(parametrize_cls.__name__, parent=collector)
            for parametrize_cls in _parametrize_cls(collector.module, obj)
        ]
    elif (
        inspect.isfunction(obj)
        and isinstance(collector, pytest.Instance)
        and plugin_base.want_method(collector.cls, obj)
    ):
        # None means, fall back to default logic, which includes
        # method-level parametrize
        return None
    else:
        # empty list means skip this item
        return []
示例#2
0
 def wantMethod(self, fn):
     if py3k:
         if not hasattr(fn.__self__, "cls"):
             return False
         cls = fn.__self__.cls
     else:
         cls = fn.im_class
     return plugin_base.want_method(cls, fn)
示例#3
0
def pytest_pycollect_makeitem(collector, name, obj):
    if inspect.isclass(obj) and plugin_base.want_class(obj):
        return pytest.Class(name, parent=collector)
    elif (inspect.isfunction(obj) and isinstance(collector, pytest.Instance)
          and plugin_base.want_method(collector.cls, obj)):
        return pytest.Function(name, parent=collector)
    else:
        return []
 def wantMethod(self, fn):
     if py3k:
         if not hasattr(fn.__self__, 'cls'):
             return False
         cls = fn.__self__.cls
     else:
         cls = fn.im_class
     return plugin_base.want_method(cls, fn)
示例#5
0
def pytest_pycollect_makeitem(collector, name, obj):
    if inspect.isclass(obj) and plugin_base.want_class(obj):
        return pytest.Class(name, parent=collector)
    elif inspect.isfunction(obj) and \
            isinstance(collector, pytest.Instance) and \
            plugin_base.want_method(collector.cls, obj):
        return pytest.Function(name, parent=collector)
    else:
        return []
示例#6
0
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:
            obj = _apply_maybe_async(obj)

        ctor = getattr(pytest.Class, "from_parent", pytest.Class)
        return [
            ctor(name=parametrize_cls.__name__, parent=collector)
            for parametrize_cls in _parametrize_cls(collector.module, obj)
        ]
    elif (inspect.isfunction(obj) and collector.cls is not None
          and plugin_base.want_method(collector.cls, obj)):
        # None means, fall back to default logic, which includes
        # method-level parametrize
        return None
    else:
        # empty list means skip this item
        return []