Exemplo n.º 1
0
    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
Exemplo n.º 2
0
            return

        failed = False
        try:
            for filename in features_files:
                feature = Feature.from_file(filename)
                results.append(feature.run(self.scenarios))
        except exceptions.LettuceSyntaxError, e:
            sys.stderr.write(e.msg)
            failed = True

        finally:
            if failed:
                raise SystemExit(2)

            total = TotalResult(results)

            call_hook('after', 'all', total)

            finished_at = datetime.now()
            time_took = finished_at - started_at

            hours = time_took.seconds / 60 / 60
            minutes = time_took.seconds / 60
            seconds = time_took.seconds
            if hours:
                print "(finished within %d hours)" % hours
            elif minutes:
                print "(finished within %d minutes)" % minutes
            elif seconds:
                print "(finished within %d seconds)" % seconds
Exemplo n.º 3
0
                                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
Exemplo n.º 4
0
        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_time = datetime.utcnow() - begin_time
            total = TotalResult(results, total_time)
            call_hook('after', 'batch')
            call_hook('after', 'all', total)

            if failed:
                raise SystemExit(2)

            return total


class ParallelRunner(Runner):
    def __init__(self,
                 base_path,
                 scenarios=None,
                 verbosity=0,
                 random=False,
Exemplo n.º 5
0
                                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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
            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_time = datetime.utcnow() - begin_time
            total = TotalResult(results, total_time)
            call_hook("after", "batch")
            call_hook("after", "all", total)

            if failed:
                raise SystemExit(2)

            return total


class ParallelRunner(Runner):
    def __init__(
        self,
        base_path,
        scenarios=None,
        verbosity=0,
Exemplo n.º 8
0
            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_time = datetime.utcnow() - begin_time
            total = TotalResult(results, total_time)
            call_hook('after', 'batch')
            total.output_format()
            call_hook('after', 'all', total)

            if failed:
                raise SystemExit(2)

            return total


class ParallelRunner(Runner):

    def __init__(self, base_path, scenarios=None, verbosity=0, random=False,
                 enable_xunit=False, xunit_filename=None,
                 enable_subunit=False, subunit_filename=None,