def test_lettuce_scenarios(): print("Running suite recipe32") lettuce.Runner(os.path.abspath("recipe32"), verbosity=3).run() print print("Running suite recipe33") lettuce.Runner(os.path.abspath("recipe33"), verbosity=3).run() print
def main(args=sys.argv[1:]): base_path = os.path.join(os.path.dirname(os.curdir), 'features') parser = optparse.OptionParser( usage="%prog or type %prog -h (--help) for help", version=lettuce.version ) parser.add_option("-v", "--verbosity", dest="verbosity", default=4, help='The verbosity level') parser.add_option("-s", "--scenarios", dest="scenarios", default=None, help='Comma separated list of scenarios to run') options, args = parser.parse_args() if args: base_path = os.path.abspath(args[0]) try: options.verbosity = int(options.verbosity) except ValueError: pass runner = lettuce.Runner(base_path, scenarios=options.scenarios, verbosity=options.verbosity) result = runner.run() if not result or result.steps != result.steps_passed: raise SystemExit(1)
def __init__(self, base_dir, what_to_run, scenarios, options): """ :param scenarios scenario numbers to run :type scenarios list :param base_dir base directory to run tests in :type base_dir: str :param what_to_run folder or file to run :type options optparse.Values :param options optparse options passed by user :type what_to_run str """ super(_LettuceRunner, self).__init__(base_dir) # TODO: Copy/Paste with lettuce.bin, need to reuse somehow # Delete args that do not exist in constructor args_to_pass = options.__dict__ runner_args = inspect.getargspec(lettuce.Runner.__init__)[0] unknown_args = set(args_to_pass.keys()) - set(runner_args) map(args_to_pass.__delitem__, unknown_args) # Tags is special case and need to be preprocessed self.__tags = None # Store tags in field if 'tags' in args_to_pass.keys() and args_to_pass['tags']: args_to_pass['tags'] = [ tag.strip('@') for tag in args_to_pass['tags'] ] self.__tags = set(args_to_pass['tags']) # Special cases we pass directly args_to_pass['base_path'] = what_to_run args_to_pass['scenarios'] = ",".join(scenarios) self.__runner = lettuce.Runner(**args_to_pass)
def __init__(self, base_dir, what_to_run, scenarios, options): """ :param scenarios scenario numbers to run :type scenarios list :param base_dir base directory to run tests in :type base_dir: str :param what_to_run folder or file to run :type options list of optparse.Option :param options optparse options passed by user :type what_to_run str """ super(_LettuceRunner, self).__init__(base_dir) # TODO: Copy/Paste with lettuce.bin, need to reuse somehow tags = None if options.tags: tags = [tag.strip('@') for tag in options.tags] self.__runner = lettuce.Runner( what_to_run, ",".join(scenarios), random=options.random, enable_xunit=options.enable_xunit, xunit_filename=options.xunit_file, enable_subunit=options.enable_subunit, subunit_filename=options.subunit_filename, failfast=options.failfast, auto_pdb=options.auto_pdb, tags=tags)
def main(args=sys.argv[1:]): base_path = os.path.join(os.path.dirname(os.curdir), 'features') parser = optparse.OptionParser( usage="%prog or type %prog -h (--help) for help", version=lettuce.version) parser.add_option("-v", "--verbosity", dest="verbosity", default=4, help='The verbosity level') parser.add_option("-s", "--scenarios", dest="scenarios", default=None, help='Comma separated list of scenarios to run') parser.add_option("-t", "--tag", dest="tags", default=None, action='append', help='Tells lettuce to run the specified tags only; ' 'can be used multiple times to define more tags' '(prefixing tags with "-" will exclude them and ' 'prefixing with "~" will match approximate words)') parser.add_option("--with-xunit", dest="enable_xunit", action="store_true", default=False, help='Output JUnit XML test results to a file') parser.add_option("--xunit-file", dest="xunit_file", default=None, type="string", help='Write JUnit XML to this file. Defaults to ' 'lettucetests.xml') options, args = parser.parse_args() if args: base_path = os.path.abspath(args[0]) try: options.verbosity = int(options.verbosity) except ValueError: pass runner = lettuce.Runner( base_path, scenarios=options.scenarios, verbosity=options.verbosity, enable_xunit=options.enable_xunit, xunit_filename=options.xunit_file, tags=options.tags, ) result = runner.run() failed = bool(result or result.steps != result.steps_passed) raise SystemExit(int(failed))
def test_after_each_all_is_executed_before_each_all(): "terrain.before.each_all and terrain.after.each_all decorators" import lettuce from lettuce.fs import FeatureLoader world.all_steps = [] mox = Mox() loader_mock = mox.CreateMock(FeatureLoader) mox.StubOutWithMock(lettuce.sys, 'path') mox.StubOutWithMock(lettuce, 'fs') mox.StubOutWithMock(lettuce.fs, 'FileSystem') mox.StubOutWithMock(lettuce, 'Feature') lettuce.fs.FeatureLoader('some_basepath').AndReturn(loader_mock) lettuce.sys.path.insert(0, 'some_basepath') lettuce.sys.path.remove('some_basepath') loader_mock.find_and_load_step_definitions() loader_mock.find_feature_files().AndReturn(['some_basepath/foo.feature']) lettuce.Feature.from_file('some_basepath/foo.feature'). \ AndReturn(Feature.from_string(FEATURE2)) mox.ReplayAll() runner = lettuce.Runner('some_basepath') CALLBACK_REGISTRY.clear() @before.all def set_state_to_before(): world.all_steps.append('before') @step('append "during" to states') def append_during_to_all_steps(step): world.all_steps.append("during") @after.all def set_state_to_after(total): world.all_steps.append('after') isinstance(total, TotalResult) runner.run() mox.VerifyAll() assert_equals( world.all_steps, ['before', 'during', 'during', 'after'], ) mox.UnsetStubs()
def __init__(self, base_dir, what_to_run, scenarios): """ :param scenarios scenario numbers to run :type scenarios list :param base_dir base directory to run tests in :type base_dir: str :param what_to_run folder or file to run :type what_to_run str """ super(_LettuceRunner, self).__init__(base_dir) self.__runner = lettuce.Runner(what_to_run, ",".join(scenarios))
def main(args=sys.argv[1:]): base_path = os.path.join(os.path.dirname(os.curdir), 'features') parser = optparse.OptionParser( usage="%prog or type %prog -h (--help) for help", version=lettuce.version) parser.add_option("-v", "--verbosity", dest="verbosity", default=4, help='The verbosity level') parser.add_option("-s", "--scenarios", dest="scenarios", default=None, help='Comma separated list of scenarios to run') parser.add_option("--with-xunit", dest="enable_xunit", action="store_true", default=False, help='Output JUnit XML test results to a file') parser.add_option("--xunit-file", dest="xunit_file", default=None, type="string", help='Write JUnit XML to this file. Defaults to ' 'lettucetests.xml') options, args = parser.parse_args() if args: base_path = os.path.abspath(args[0]) try: options.verbosity = int(options.verbosity) except ValueError: pass runner = lettuce.Runner( base_path, scenarios=options.scenarios, verbosity=options.verbosity, enable_xunit=options.enable_xunit, xunit_filename=options.xunit_file, ) result = runner.run() if not result or result.steps != result.steps_passed: raise SystemExit(1)
def prepareTestRunner(self, runner): """Create and run the lettuce runner. This does not provide a real test runner for lettuce tests, but runs the lettuce test runner. So, there are no real test results and """ lrunner = lettuce.Runner(self._base_path, verbosity=self.conf.lettuce_verbosity, scenarios=self.conf.lettuce_scenarios) result = lrunner.run() if not result or result.steps != result.steps_passed: # I really don't have any idea how to handle this properly. raise RuntimeError("Lettuce test suite failed") return runner
def inspect(self, openstack): runner = lettuce.Runner(base_path=self.base_path) lettuce.world.openstack = openstack result = runner.run() del lettuce.world.openstack for feature_result in result.feature_results: for scenario_result in feature_result.scenario_results: if scenario_result.passed: continue for step in scenario_result.steps_undefined: openstack.report_issue( Issue(Issue.ERROR, 'Undefined step "%s"' % step.sentence))
def main(args=sys.argv[1:]): base_path = os.path.join(os.path.dirname(os.curdir), 'features') parser = optparse.OptionParser( usage="%prog or type %prog -h (--help) for help", version=lettuce.version) parser.add_option("-v", "--verbosity", dest="verbosity", default=4, help='The verbosity level') parser.add_option("-s", "--scenarios", dest="scenarios", default=None, help='Comma separated list of scenarios to run') parser.add_option("-t", "--tag", dest="tags", default=None, action='append', help='Tells lettuce to run the specified tags only; ' 'can be used multiple times to define more tags' '(prefixing tags with "-" will exclude them and ' 'prefixing with "~" will match approximate words)') parser.add_option( "-r", "--random", dest="random", action="store_true", default=False, help="Run scenarios in a more random order to avoid interference") parser.add_option("-p", "--parallel", dest="parallel", default=None, help="Run scenarios in a parallel fashion") parser.add_option("--with-xunit", dest="enable_xunit", action="store_true", default=False, help='Output JUnit XML test results to a file') parser.add_option("--xunit-file", dest="xunit_file", default=None, type="string", help='Write JUnit XML to this file. Defaults to ' 'lettucetests.xml') parser.add_option("--with-subunit", dest="enable_subunit", action="store_true", default=False, help='Output Subunit test results to a file') parser.add_option("--subunit-file", dest="subunit_filename", default=None, help='Write Subunit data to this file. Defaults to ' 'subunit.bin') parser.add_option("--failfast", dest="failfast", default=False, action="store_true", help='Stop running in the first failure') parser.add_option("--pdb", dest="auto_pdb", default=False, action="store_true", help='Launches an interactive debugger upon error') options, args = parser.parse_args(args) if args: base_path = os.path.abspath(args[0]) try: options.verbosity = int(options.verbosity) except ValueError: pass tags = None if options.tags: tags = [tag.strip('@') for tag in options.tags] if options.parallel: print "running Parallel Runner with {} workers".format( options.parallel) runner = lettuce.ParallelRunner( base_path, scenarios=options.scenarios, verbosity=options.verbosity, random=options.random, enable_xunit=options.enable_xunit, xunit_filename=options.xunit_file, enable_subunit=options.enable_subunit, subunit_filename=options.subunit_filename, failfast=options.failfast, auto_pdb=options.auto_pdb, tags=tags, workers=int(options.parallel)) else: runner = lettuce.Runner(base_path, scenarios=options.scenarios, verbosity=options.verbosity, random=options.random, enable_xunit=options.enable_xunit, xunit_filename=options.xunit_file, enable_subunit=options.enable_subunit, subunit_filename=options.subunit_filename, failfast=options.failfast, auto_pdb=options.auto_pdb, tags=tags) result = runner.run() failed = result is None or result.steps != result.steps_passed raise SystemExit(int(failed))
def run(self): try: return lettuce.Runner(**self.run_args).run() except BaseException: print "Lettuce raised the following exception:" raise
def main(args=sys.argv[1:]): base_path = os.path.join(os.path.dirname(os.curdir), 'features') parser = optparse.OptionParser( usage="%prog or type %prog -h (--help) for help", version=lettuce.version) parser.add_option("-v", "--verbosity", dest="verbosity", default=4, help='The verbosity level') parser.add_option("-s", "--scenarios", dest="scenarios", default=None, help='Comma separated list of scenarios to run') parser.add_option("-t", "--tag", dest="tags", default=None, action='append', help='Tells lettuce to run the specified tags only; ' 'can be used multiple times to define more tags' '(prefixing tags with "-" will exclude them and ' 'prefixing with "~" will match approximate words)') parser.add_option( "-r", "--random", dest="random", action="store_true", default=False, help="Run scenarios in a more random order to avoid interference") parser.add_option("--with-xunit", dest="enable_xunit", action="store_true", default=False, help='Output JUnit XML test results to a file') parser.add_option("--xunit-file", dest="xunit_file", default=None, type="string", help='Write JUnit XML to this file. Defaults to ' 'lettucetests.xml') parser.add_option("--failfast", dest="failfast", default=False, action="store_true", help='Stop running in the first failure') parser.add_option("--pdb", dest="auto_pdb", default=False, action="store_true", help='Launches an interactive debugger upon error') parser.add_option("--plugins-dir", dest="plugins_dir", default=None, type="string", help='Sets plugins directory') parser.add_option("--terrain-file", dest="terrain_file", default=None, type="string", help='Sets terrain file') parser.add_option( "--files-to-load", dest="files_to_load", default=None, type="string", help='Usage: \n' 'lettuce some/dir --files-to-load file1[,file2[,file3...]]' '\n' 'Defines list of .py files that needs to be loaded. ' 'You can use regular expressions for filenames. ' 'Use either this option or --excluded-files, ' 'but not them both.') parser.add_option( "--excluded-files", dest="excluded_files", default=None, type="string", help='Usage: \n' 'lettuce some/dir --files-to-load file1[,file2[,file3...]]' '\n' 'Defines list of .py files that should not be loaded. ' 'You can use regular expressions for filenames. ' 'Use either this option, or --files-to-load, ' 'but not them both.') options, args = parser.parse_args(args) if args: base_path = os.path.abspath(args[0]) try: options.verbosity = int(options.verbosity) except ValueError: pass tags = None if options.tags: tags = [tag.strip('@') for tag in options.tags] # Terrain file loading feature_dir = base_path if not base_path.endswith('.feature') \ else os.path.dirname(base_path) terrain_file = options.terrain_file or \ os.environ.get('LETTUCE_TERRAIN_FILE', os.path.join(feature_dir, 'terrain')) if not os.path.exists(terrain_file + '.py'): terrain_file = 'terrain' lettuce.import_terrain(terrain_file) # Plugins loading plugins_dir = options.plugins_dir or os.environ.get( 'LETTUCE_TERRAIN_FILE', None) if plugins_dir: lettuce.import_plugins(options.plugins_dir) # Find files to load that are defined in .feature file files_to_load = None excluded_files = None if options.files_to_load: files_to_load = options.files_to_load.split(',') elif options.excluded_files: excluded_files = options.excluded_files.split(',') else: files_to_load = find_files_to_load(base_path) # Create and run lettuce runner instance runner = lettuce.Runner( base_path, scenarios=options.scenarios, verbosity=options.verbosity, random=options.random, enable_xunit=options.enable_xunit, xunit_filename=options.xunit_file, failfast=options.failfast, auto_pdb=options.auto_pdb, tags=tags, files_to_load=files_to_load, excluded_files=excluded_files, ) result = runner.run() failed = result is None or result.steps != result.steps_passed raise SystemExit(int(failed))
def main(args=sys.argv[1:]): # modified base path to run test/features instead of features base_path = os.path.join(os.path.dirname(os.curdir), 'test', 'features') parser = optparse.OptionParser( usage="%prog or type %prog -h (--help) for help", version=lettuce.version) parser.add_option("-v", "--verbosity", dest="verbosity", default=4, help='The verbosity level') # TODO add in more browsers parser.add_option("-b", "--browser", help="Choose the browser to run these tests under", choices=['chrome', 'firefox']) parser.add_option("-s", "--scenarios", dest="scenarios", default=None, help='Comma separated list of scenarios to run') parser.add_option("-t", "--tag", dest="tags", default=None, action='append', help='Tells lettuce to run the specified tags only; ' 'can be used multiple times to define more tags' '(prefixing tags with "-" will exclude them and ' 'prefixing with "~" will match approximate words)') parser.add_option( "-r", "--random", dest="random", action="store_true", default=False, help="Run scenarios in a more random order to avoid interference") parser.add_option("--with-xunit", dest="enable_xunit", action="store_true", default=False, help='Output JUnit XML test results to a file') parser.add_option("--xunit-file", dest="xunit_file", default=None, type="string", help='Write JUnit XML to this file. Defaults to ' 'lettucetests.xml') parser.add_option("--failfast", dest="failfast", default=False, action="store_true", help='Stop running in the first failure') parser.add_option("--pdb", dest="auto_pdb", default=False, action="store_true", help='Launches an interactive debugger upon error') options, args = parser.parse_args(args) if args: base_path = os.path.abspath(args[0]) try: options.verbosity = int(options.verbosity) except ValueError: pass tags = None if options.tags: tags = [tag.strip('@') for tag in options.tags] runner = lettuce.Runner( base_path, scenarios=options.scenarios, verbosity=options.verbosity, random=options.random, enable_xunit=options.enable_xunit, xunit_filename=options.xunit_file, failfast=options.failfast, auto_pdb=options.auto_pdb, tags=tags, ) if options.browser == 'chrome': world.browser = webdriver.Chrome() elif options.browser == 'firefox': world.browser = webdriver.Firefox() else: world.browser = None result = runner.run() failed = result is None or result.steps != result.steps_passed raise SystemExit(int(failed))