def collect_setup_files(context): """ Searches feature files in 'setup' directory for any configured setup features and adds them to the context of the current run. This is done before_all so that the setup features are available during the run. """ setup_files = os.path.join(context.config.base_dir, settings.SETUP_DIR) logger.info(f'Parsing setup files from the {setup_files} directory.') feature_locations = collect_feature_locations([setup_files]) all_features = parse_features(feature_locations) context_setup = {} for feature in all_features: tag_name = None for tag in feature.tags: if tag.startswith('configure.'): tag_name = tag.replace('configure.', '') break if not tag_name: # This was not a configuration, so skip the feature continue logger.info( f'Setting Context Setup {tag_name} from {feature.location}.') setup = {'setup': [], 'teardown': []} for scenario in feature.scenarios: if any(tag == 'teardown' for tag in scenario.tags): logger.info(f'Setting teardown from {scenario.location}.') setup['teardown'].append(scenario) elif any(tag == 'setup' for tag in scenario.tags): logger.info(f'Setting setup from {scenario.location}.') setup['setup'].append(scenario) context_setup[tag_name] = setup context.context_setup = context_setup
def run_with_paths(self): """ overloading this so i can use HackedContext """ self.context = HackedContext(self) self.context.listeners = self.listeners self.context.webdriver_url = self.webdriver_url self.context.webdriver_processor = self.webdriver_processor self.load_hooks() self.load_step_definitions() # -- ENSURE: context.execute_steps() works in weird cases (hooks, ...) # self.setup_capture() # self.run_hook('before_all', self.context) # -- STEP: Parse all feature files (by using their file location). feature_locations = [filename for filename in self.feature_locations() if not self.config.exclude(filename)] features = parse_features(feature_locations, language=self.config.lang) self.features.extend(features) # -- STEP: Run all features. stream_openers = self.config.outputs self.formatters = formatters.get_formatter(self.config, stream_openers) return self.run_model()
def run_with_paths(self): self.load_hooks() self.load_step_definitions() context = self.context = Context(self) assert not self.aborted # -- ENSURE: context.execute_steps() works in weird cases (hooks, ...) self.setup_capture() stream_openers = self.config.outputs failed_count = 0 self.run_hook('before_all', context) # -- STEP: Parse all feature files (by using their file location). feature_locations = [ filename for filename in self.feature_locations() if not self.config.exclude(filename) ] features = parse_features(feature_locations, language=self.config.lang) self.features.extend(features) # -- STEP: Run all features. self.formatters = formatters.get_formatter(self.config, stream_openers) undefined_steps_initial_size = len(self.undefined) run_feature = True for feature in features: if run_feature: try: self.feature = feature for formatter in self.formatters: formatter.uri(feature.filename) failed = feature.run(self) if failed: failed_count += 1 if self.config.stop or self.aborted: # -- FAIL-EARLY: After first failure. run_feature = False except KeyboardInterrupt: self.aborted = True failed_count += 1 run_feature = False # -- ALWAYS: Report run/not-run feature to reporters. # REQUIRED-FOR: Summary to keep track of untested features. for reporter in self.config.reporters: reporter.feature(feature) # -- AFTER-ALL: if self.aborted: print "\nABORTED: By user." for formatter in self.formatters: formatter.close() self.run_hook('after_all', context) for reporter in self.config.reporters: reporter.end() # if self.aborted: # print "\nABORTED: By user." failed = ((failed_count > 0) or self.aborted or (len(self.undefined) > undefined_steps_initial_size)) return failed
def run_with_paths(self): context = self.context = Context(self) self.load_hooks() self.load_step_definitions() assert not self.aborted stream_openers = self.config.outputs failed_count = 0 # -- ENSURE: context.execute_steps() works in weird cases (hooks, ...) self.setup_capture() self.run_hook('before_all', context) # -- STEP: Parse all feature files (by using their file location). feature_locations = [ filename for filename in self.feature_locations() if not self.config.exclude(filename) ] features = parse_features(feature_locations, language=self.config.lang) self.features.extend(features) # -- STEP: Run all features. self.formatters = formatters.get_formatter(self.config, stream_openers) undefined_steps_initial_size = len(self.undefined) run_feature = True for feature in features: if run_feature: try: self.feature = feature for formatter in self.formatters: formatter.uri(feature.filename) failed = feature.run(self) if failed: failed_count += 1 if self.config.stop or self.aborted: # -- FAIL-EARLY: After first failure. run_feature = False except KeyboardInterrupt: self.aborted = True failed_count += 1 run_feature = False # -- ALWAYS: Report run/not-run feature to reporters. # REQUIRED-FOR: Summary to keep track of untested features. for reporter in self.config.reporters: reporter.feature(feature) # -- AFTER-ALL: if self.aborted: print "\nABORTED: By user." for formatter in self.formatters: formatter.close() self.run_hook('after_all', context) for reporter in self.config.reporters: reporter.end() # if self.aborted: # print "\nABORTED: By user." failed = ((failed_count > 0) or self.aborted or (len(self.undefined) > undefined_steps_initial_size)) return failed
def load_scenarios(): paths = (Path(__file__).parent / "config/features/").glob("*.feature") features = parse_features([str(p) for p in paths], language="fr") scenarios = [] for feature in features: for scenario in feature.scenarios: scenarios.append(load_scenario(feature, scenario)) return scenarios
def run_with_paths(self): self.context = Context(self) self.load_hooks() self.load_step_definitions() # -- ENSURE: context.execute_steps() works in weird cases (hooks, ...) # self.setup_capture() # self.run_hook('before_all', self.context) # -- STEP: Parse all feature files (by using their file location). feature_locations = [filename for filename in self.feature_locations() if not self.config.exclude(filename)] features = parse_features(feature_locations, language=self.config.lang) self.features.extend(features) # -- STEP: Run all features. stream_openers = self.config.outputs self.formatters = make_formatters(self.config, stream_openers) return self.run_model()
def load_features(self,filter_params={}): self.features = [] self.config = copy.copy(self.config) feature_locations = [ filename for filename in self.feature_locations() if not self.config.exclude(filename) ] features = parse_features(feature_locations, language=self.config.lang) self.features.extend(features) #make a feature deep copy for launch in threads # for feature in self.features: # #make a copy of scenarios objects with steps # feature.scenarios = [ copy.copy(scenario) for scenario in feature.walk_scenarios() ] # for scenario in feature.walk_scenarios(): # if scenario._background_steps: # scenario._background_steps = copy.deepcopy(scenario._background_steps) # scenario.steps = copy.deepcopy(scenario.steps) # #for step in scenario.all_steps: # # #print scenario,id(scenario),step.name,id(step) self.filter_features(filter_params) return self
def run_with_paths(self): self.context = Context(self) self.load_hooks() self.load_step_definitions() # -- ENSURE: context.execute_steps() works in weird cases (hooks, ...) # self.setup_capture() # self.run_hook("before_all", self.context) # -- STEP: Parse all feature files (by using their file location). feature_locations = [filename for filename in self.feature_locations() if not self.config.exclude(filename)] features = parse_features(feature_locations, language=self.config.lang) self.features.extend(features) # -- STEP: Run all features. stream_openers = self.config.outputs self.formatters = make_formatters(self.config, stream_openers) return self.run_model()
def run_with_paths(self): feature_locations = [ filename for filename in self.feature_locations() if not self.config.exclude(filename) ] self.load_hooks( ) # hooks themselves not used, but 'environment.py' loaded # step definitions are needed here for formatters only self.load_step_definitions() features = parse_features(feature_locations, language=self.config.lang) self.features.extend(features) feature_count, scenario_count = self.scan_features() njobs = len(self.jobs_map) proc_count = int(self.config.proc_count) print(("INFO: {0} scenario(s) and {1} feature(s) queued for" " consideration by {2} workers. Some may be skipped if the" " -t option was given...".format(scenario_count, feature_count, proc_count))) procs = [] old_outs = self.config.outputs self.config.outputs = [] old_reporters = self.config.reporters self.config.reporters = [] for i in range(proc_count): client = MultiProcClientRunner(self, i) p = multiprocessing.Process(target=client.run) procs.append(p) p.start() del p print(("INFO: started {0} workers for {1} jobs.".format( proc_count, njobs))) self.config.reporters = old_reporters self.formatters = make_formatters(self.config, old_outs) self.config.outputs = old_outs while (not self.jobsq.empty()): # 1: consume while tests are running self.consume_results() if not any([p.is_alive() for p in procs]): break if any([p.is_alive() for p in procs]): self.jobsq.join() # wait for all jobs to be processed print("INFO: all jobs have been processed") while self.consume_results(timeout=0.1): # 2: remaining results pass # then, wait for all workers to exit: [p.join() for p in procs] print("INFO: all sub-processes have returned") while self.consume_results(timeout=0.1): # 3: just in case some arrive late in the pipe pass for f in self.features: # make sure all features (including ones that have not returned) # are printed self._output_feature(f) for formatter in self.formatters: formatter.close() for reporter in self.config.reporters: reporter.end() return self.results_fail