def run(self): """ Find and load step definitions, and them find and load features under `base_path` specified on constructor """ results = [] if self.single_feature: features_files = [self.single_feature] else: features_files = self.loader.find_feature_files() if self.random: random.shuffle(features_files) if not features_files: self.output.print_no_features_found(self.loader.base_dir) return # only load steps if we've located some features. # this prevents stupid bugs when loading django modules # that we don't even want to test. try: self.loader.find_and_load_step_definitions() except StepLoadingError as e: print("Error loading step definitions:\n", e) return call_hook('before', 'all') failed = False try: for filename in features_files: feature = Feature.from_file(filename) results.append( feature.run(self.scenarios, tags=self.tags, random=self.random, failfast=self.failfast)) except exceptions.LettuceSyntaxError as e: sys.stderr.write(e.msg) failed = True except: if not self.failfast: e = sys.exc_info()[1] print("Died with %s" % str(e)) traceback.print_exc() else: print("Lettuce aborted running any more tests " "because was called with the `--failfast` option") failed = True finally: total = TotalResult(results) total.output_format() call_hook('after', 'all', total) if failed: raise SystemExit(2) return total
failfast=self.failfast)) except exceptions.LettuceSyntaxError as e: sys.stderr.write(e.msg) failed = True except exceptions.NoDefinitionFound, e: sys.stderr.write(e.msg) failed = True except: if not self.failfast: e = sys.exc_info()[1] print "Died with %s" % str(e) traceback.print_exc() else: print print( "Lettuce aborted running any more tests " "because was called with the `--failfast` option") failed = True finally: total = TotalResult(results) total.output_format() call_hook('after', 'all', total) if failed: raise LettuceRunnerError("Test failed.") return total
random=self.random, failfast=self.failfast)) except exceptions.LettuceSyntaxError as e: sys.stderr.write(e.msg) failed = True except exceptions.NoDefinitionFound, e: sys.stderr.write(e.msg) failed = True except: if not self.failfast: e = sys.exc_info()[1] print "Died with %s" % str(e) traceback.print_exc() else: print print ("Lettuce aborted running any more tests " "because was called with the `--failfast` option") failed = True finally: total = TotalResult(results) total.output_format() call_hook('after', 'all', total) if failed: raise LettuceRunnerError("Test failed.") return total
def run(self): """ Find and load step definitions, and them find and load features under `base_path` specified on constructor """ CALLBACK_REGISTRY.clear(name='output') CALLBACK_REGISTRY.clear(name='common_output') if self.verbosity is 0: from lettuce.plugins import non_verbose as output elif self.verbosity is 1: from lettuce.plugins import dots as output elif self.verbosity is 2: from lettuce.plugins import scenario_names as output elif self.verbosity is 3: from lettuce.plugins import shell_output as output else: from lettuce.plugins import colored_shell_output as output reload(output) self.output = output results = [] if self.single_feature: features_files = [self.single_feature] else: features_files = self.loader.find_feature_files() if self.random: random.shuffle(features_files) if not features_files: self.output.print_no_features_found(self.loader.base_dir) return # only load steps if we've located some features. # this prevents stupid bugs when loading django modules # that we don't even want to test. try: self.loader.find_and_load_step_definitions() except StepLoadingError as e: print "Error loading step definitions:\n", e raise SystemExit(3) failed = False try: call_hook('before', 'all') for filename in features_files: feature = Feature.from_file(filename) results.append( feature.run(self.scenarios, tags=self.tags, random=self.random, failfast=self.failfast)) except exceptions.LettuceSyntaxError as e: sys.stderr.write(e.msg) failed = True except exceptions.FailFast: print print ("Lettuce aborted running any more tests " "because was called with the `--failfast` option") failed = True except Exception: # ensure our output is undiverted sys.stdout = real_stdout print "Exception in Lettuce itself!" failed = True raise except BaseException: failed = True raise finally: total = TotalResult(results) total.output_format() call_hook('after', 'all', total) if not total.passed: failed = True if failed: raise SystemExit(2) return total