def printErrors(self): log.debug('printErrors called') _TextTestResult.printErrors(self) self.printErrorList('DEPRECATED', self.deprecated) self.printErrorList('SKIPPED', self.skip) log.debug('calling plugin reports') call_plugins(self.conf.plugins, 'report', self.stream)
def wantFile(self, file, package=None): """Is the file a wanted test file? If self.tests is defined, the file must match the file part of a test address in self.tests. The default implementation ignores the package setting, but it is passed in case plugins need to distinguish package from non-package files. """ # never, ever load files that match anything in ignore # (.* _* and *setup*.py by default) base = os.path.basename(file) ignore_matches = [ ignore_this for ignore_this in self.ignoreFiles if ignore_this.search(base) ] if ignore_matches: log.debug('%s matches ignoreFiles pattern; skipped', base) return False if not self.conf.includeExe and os.access(file, os.X_OK): log.info('%s is executable; skipped', file) return False in_tests = self.fileInTests(file) if not in_tests: return False dummy, ext = os.path.splitext(base) pysrc = ext == '.py' wanted = pysrc and self.matches(base) plug_wants = call_plugins(self.plugins, 'wantFile', file, package) if plug_wants is not None: wanted = plug_wants return wanted or (pysrc and self.tests and in_tests)
def addError(self, test, err): if self.isDeprecated(err): self.addDeprecated(test) elif self.isSkip(err): self.addSkip(test) else: self.capt = self.getBuffer() if self.conf.debugErrors: if self.conf.capture: end_capture() pdb.post_mortem(err[2]) if self.conf.capture: start_capture() self.resetBuffer() call_plugins(self.conf.plugins, 'addError', test, err, self.capt) if self.conf.stopOnError: self.shouldStop = True
def addFailure(self, test, err): self.capt = self.getBuffer() if self.conf.debugFailures: if self.conf.capture: end_capture() pdb.post_mortem(err[2]) if self.conf.capture: start_capture() if self.conf.detailedErrors: try: self.tbinfo = inspect_traceback(err[2]) except tokenize.TokenError: self.tbinfo = "ERR: unable to inspect traceback" else: self.tbinfo = '' self.resetBuffer() call_plugins(self.conf.plugins, 'addFailure', test, err, self.capt, self.tbinfo) if self.conf.stopOnError: self.shouldStop = True
def wantModule(self, module): """Is the module a test module? The tail of the module name must match test requirements. If a module is wanted, it means that the module should be loaded, and its setup/teardown fixtures run -- if any. It does not mean that tests will be collected from the module; tests are only collected from modules where wantModuleTests() is true. """ in_tests = self.moduleInTests(module, either=True) if not in_tests: return False wanted = self.matches(module.__name__.split('.')[-1]) plug_wants = call_plugins(self.plugins, 'wantModule', module) if plug_wants is not None: wanted = plug_wants return wanted or (self.tests and in_tests)
def wantClass(self, cls): """Is the class a wanted test class? A class must be a unittest.TestCase subclass, or match test name requirements. If self.tests is defined, the class must match something in self.tests: """ log.debug("Load tests from class %s?", cls) wanted = (not cls.__name__.startswith('_') and (issubclass(cls, unittest.TestCase) or self.match.search(cls.__name__))) log.debug("%s is wanted? %s", cls, wanted) plug_wants = call_plugins(self.plugins, 'wantClass', cls) if plug_wants is not None: log.debug("Plugin setting selection of %s to %s", cls, plug_wants) wanted = plug_wants return wanted and self.classInTests(cls)
def wantModuleTests(self, module): """Collect tests from this module? The tail of the module name must match test requirements. If the modules tests are wanted, they will be collected by the standard test collector. If your plugin wants to collect tests from a module in some other way, it MUST NOT return true for wantModuleTests; that would not allow the plugin to collect tests, but instead cause the standard collector to collect tests. """ in_tests = self.moduleInTests(module) if not in_tests: return False # unittest compat: always load from __main__ wanted = (self.matches(module.__name__.split('.')[-1]) or module.__name__ == '__main__') plug_wants = call_plugins(self.plugins, 'wantModuleTests', module) if plug_wants is not None: wanted = plug_wants return wanted or (self.tests and in_tests)
def wantMethod(self, method): """Is the method a test method? If conf.function_only is defined, the qualified method name (class.method) must match function_only. Otherwise, the base method name must match test requirements. """ try: method_name = method.__name__ except AttributeError: # not a method return False if method_name.startswith('_'): # never collect 'private' methods return False in_tests = self.methodInTests(method) if not in_tests: return False wanted = self.matches(method_name) plug_wants = call_plugins(self.plugins, 'wantMethod', method) if plug_wants is not None: wanted = plug_wants return wanted
def wantFunction(self, function): """Is the function a test function? If conf.function_only is defined, the function name must match function_only. Otherwise, the function name must match test requirements. """ try: if hasattr(function, 'compat_func_name'): funcname = function.compat_func_name else: funcname = function.__name__ except AttributeError: # not a function return False in_tests = self.funcInTests(function) if not in_tests: return False wanted = not funcname.startswith('_') and self.matches(funcname) plug_wants = call_plugins(self.plugins, 'wantFunction', function) if plug_wants is not None: wanted = plug_wants return wanted
def wantDirectory(self, dirname): """Is the directory a wanted test directory? All package directories match, so long as they do not match exclude. All other directories must match test requirements. """ init = os.path.join(dirname, '__init__.py') tail = os.path.basename(dirname) if os.path.exists(init): wanted = (not self.exclude or not filter(None, [exc.search(tail) for exc in self.exclude] )) else: wanted = (self.matches(tail) or (self.conf.srcDirs and tail in self.conf.srcDirs)) plug_wants = call_plugins(self.plugins, 'wantDirectory', dirname) if plug_wants is not None: wanted = plug_wants # FIXME in tests? return wanted
def addSuccess(self, test): self.capt = self.getBuffer() self.resetBuffer() call_plugins(self.conf.plugins, 'addSuccess', test, self.capt)
def addSkip(self, test): self.resetBuffer() call_plugins(self.conf.plugins, 'addSkip', test)
def addDeprecated(self, test): self.resetBuffer() call_plugins(self.conf.plugins, 'addDeprecated', test)
def stopTest(self, test): if self.conf.capture: self.resetBuffer() self.capt = None self.tbinfo = None call_plugins(self.conf.plugins, 'stopTest', test)