コード例 #1
0
    def collect(self):
        from unittest import TestLoader

        cls = self.obj
        if not getattr(cls, "__test__", True):
            return
        self.session._fixturemanager.parsefactories(self, unittest=True)
        loader = TestLoader()
        module = self.getparent(Module).obj
        foundsomething = False
        for name in loader.getTestCaseNames(self.obj):
            x = getattr(self.obj, name)
            if not getattr(x, "__test__", True):
                continue
            funcobj = getimfunc(x)
            transfer_markers(funcobj, cls, module)
            yield TestCaseFunction(name, parent=self, callobj=funcobj)
            foundsomething = True

        if not foundsomething:
            runtest = getattr(self.obj, "runTest", None)
            if runtest is not None:
                ut = sys.modules.get("twisted.trial.unittest", None)
                if ut is None or runtest != ut.TestCase.runTest:
                    yield TestCaseFunction("runTest", parent=self)
コード例 #2
0
ファイル: unittest.py プロジェクト: kalekundert/pytest
    def collect(self):
        from unittest import TestLoader

        cls = self.obj
        if not getattr(cls, "__test__", True):
            return
        self.session._fixturemanager.parsefactories(self, unittest=True)
        loader = TestLoader()
        module = self.getparent(Module).obj
        foundsomething = False
        for name in loader.getTestCaseNames(self.obj):
            x = getattr(self.obj, name)
            if not getattr(x, "__test__", True):
                continue
            funcobj = getattr(x, "im_func", x)
            transfer_markers(funcobj, cls, module)
            yield TestCaseFunction(name, parent=self, callobj=funcobj)
            foundsomething = True

        if not foundsomething:
            runtest = getattr(self.obj, "runTest", None)
            if runtest is not None:
                ut = sys.modules.get("twisted.trial.unittest", None)
                if ut is None or runtest != ut.TestCase.runTest:
                    yield TestCaseFunction("runTest", parent=self)
コード例 #3
0
ファイル: unittest.py プロジェクト: lichinka/cai
 def collect(self):
     loader = py.std.unittest.TestLoader()
     module = self.getparent(pytest.Module).obj
     cls = self.obj
     for name in loader.getTestCaseNames(self.obj):
         x = getattr(self.obj, name)
         funcobj = getattr(x, 'im_func', x)
         transfer_markers(funcobj, cls, module)
         if hasattr(funcobj, 'todo'):
             pytest.mark.xfail(reason=str(funcobj.todo))(funcobj)
         yield TestCaseFunction(name, parent=self)
コード例 #4
0
ファイル: unittest.py プロジェクト: snim2/rcsp
 def collect(self):
     loader = py.std.unittest.TestLoader()
     module = self.getparent(pytest.Module).obj
     cls = self.obj
     for name in loader.getTestCaseNames(self.obj):
         x = getattr(self.obj, name)
         funcobj = getattr(x, 'im_func', x)
         transfer_markers(funcobj, cls, module)
         if hasattr(funcobj, 'todo'):
             pytest.mark.xfail(reason=str(funcobj.todo))(funcobj)
         yield TestCaseFunction(name, parent=self)
コード例 #5
0
def pytest_pycollect_makeitem(collector, name, obj):
    """A pytest hook to collect asyncio coroutines."""
    if collector.funcnamefilter(name) and _is_coroutine(obj):
        item = pytest.Function(name, parent=collector)

        # Due to how pytest test collection works, module-level pytestmarks
        # are applied after the collection step. Since this is the collection
        # step, we look ourselves.
        transfer_markers(obj, item.cls, item.module)
        item = pytest.Function(name, parent=collector)  # To reload keywords.

        if 'asyncio' in item.keywords:
            return list(collector._genfunctions(name, obj))
コード例 #6
0
ファイル: plugin.py プロジェクト: roger-strain/launch
def pytest_pycollect_makeitem(collector, name, obj):
    """Collect coroutine based launch tests."""
    if collector.funcnamefilter(name) and is_valid_test_item(obj):
        item = from_parent(pytest.Function, parent=collector, name=name)

        # Due to how pytest test collection works, module-level pytestmarks
        # are applied after the collection step. Since this is the collection
        # step, we look ourselves.
        transfer_markers(obj, item.cls, item.module)
        item = from_parent(pytest.Function, parent=collector,
                           name=name)  # To reload keywords.

        if is_launch_test(item):
            if not is_launch_test_mark_valid(item):
                # return an item with a warning that's going to be skipped
                msg = (
                    '"fixture" keyword argument is required in a pytest.mark.launch() '
                    'decorator')
                item.warn(LaunchTestWarning(msg))
                item.add_marker(pytest.mark.skip(msg))
                return [item]
            fixture = get_launch_test_fixture(item)
            fixturename = fixture.__name__
            scope = fixture._pytestfixturefunction.scope
            is_shutdown = has_shutdown_kwarg(item)
            items = generate_test_items(collector,
                                        name,
                                        obj,
                                        fixturename,
                                        is_shutdown=is_shutdown,
                                        needs_renaming=False)
            if need_shutdown_test_item(obj) and scope != 'function':
                # for function scope we only need one shutdown item
                # if not we're going to use two event loops!!!
                shutdown_items = generate_test_items(collector,
                                                     name,
                                                     obj,
                                                     fixturename,
                                                     is_shutdown=True,
                                                     needs_renaming=True)
                for item, shutdown_item in zip(items, shutdown_items):
                    item._launch_pytest_shutdown_item = shutdown_item
                items.extend(shutdown_items)
            return items
コード例 #7
0
ファイル: unittest.py プロジェクト: Darriall/pypy
    def collect(self):
        self.session._fixturemanager.parsefactories(self, unittest=True)
        loader = py.std.unittest.TestLoader()
        module = self.getparent(pytest.Module).obj
        cls = self.obj
        foundsomething = False
        for name in loader.getTestCaseNames(self.obj):
            x = getattr(self.obj, name)
            funcobj = getattr(x, 'im_func', x)
            transfer_markers(funcobj, cls, module)
            yield TestCaseFunction(name, parent=self)
            foundsomething = True

        if not foundsomething:
            runtest = getattr(self.obj, 'runTest', None)
            if runtest is not None:
                ut = sys.modules.get("twisted.trial.unittest", None)
                if ut is None or runtest != ut.TestCase.runTest:
                    yield TestCaseFunction('runTest', parent=self)
コード例 #8
0
ファイル: unittest.py プロジェクト: HavlicekFilip/ukol-site
    def collect(self):
        self.session._fixturemanager.parsefactories(self, unittest=True)
        loader = py.std.unittest.TestLoader()
        module = self.getparent(pytest.Module).obj
        cls = self.obj
        foundsomething = False
        for name in loader.getTestCaseNames(self.obj):
            x = getattr(self.obj, name)
            funcobj = getattr(x, 'im_func', x)
            transfer_markers(funcobj, cls, module)
            yield TestCaseFunction(name, parent=self)
            foundsomething = True

        if not foundsomething:
            runtest = getattr(self.obj, 'runTest', None)
            if runtest is not None:
                ut = sys.modules.get("twisted.trial.unittest", None)
                if ut is None or runtest != ut.TestCase.runTest:
                    yield TestCaseFunction('runTest', parent=self)