Exemplo n.º 1
0
    def _getTestCaseNames(self, event, testCaseClass):
        excluded = set()

        def isTestMethod(attrname,
                         testCaseClass=testCaseClass,
                         excluded=excluded):
            prefix = evt.testMethodPrefix or self.session.testMethodPrefix
            return (attrname.startswith(prefix)
                    and hasattr(getattr(testCaseClass, attrname), '__call__')
                    and attrname not in excluded)

        evt = events.GetTestCaseNamesEvent(event.loader, testCaseClass,
                                           isTestMethod)
        result = self.session.hooks.getTestCaseNames(evt)
        if evt.handled:
            test_names = result or []
        else:
            excluded.update(evt.excludedNames)
            test_names = [
                entry for entry in dir(testCaseClass) if isTestMethod(entry)
            ]
        if evt.extraNames:
            test_names.extend(evt.extraNames)
        sortkey = getattr(testCaseClass, 'sortTestMethodsUsing',
                          event.loader.sortTestMethodsUsing)
        if sortkey:
            test_names.sort(key=sortkey)
        return test_names
Exemplo n.º 2
0
    def _getTestCaseNames(self, event, testCaseClass):
        """Function to get all tests inside a testcase. Those tests must be callable and include in their names the session's testMethodPrefix. 
                            This function launch the hook getTestCaseNames which is defined in this plugin."""
        excluded = set()

        def isTestMethod(attrname,
                         testCaseClass=testCaseClass,
                         excluded=excluded):
            prefix = evt.testMethodPrefix or self.session.testMethodPrefix
            return (attrname.startswith(prefix)
                    and hasattr(getattr(testCaseClass, attrname), '__call__')
                    and attrname not in excluded)

        evt = events.GetTestCaseNamesEvent(event.loader, testCaseClass,
                                           isTestMethod)
        result = self.session.hooks.getTestCaseNames(evt)
        if evt.handled:
            test_names = result or []
        else:
            excluded.update(evt.excludedNames)
            test_names = [
                entry for entry in dir(testCaseClass) if isTestMethod(entry)
            ]
        if evt.extraNames:
            test_names.extend(evt.extraNames)
        sortkey = getattr(testCaseClass, 'sortTestMethodsUsing',
                          event.loader.sortTestMethodsUsing)
        if sortkey:
            test_names.sort(key=sortkey)
        return test_names