Best Python code snippet using behave
__main__.py
Source:__main__.py
...53 if config.lang_list:54 print_language_list()55 return 056 if config.lang_help:57 print_language_help(config)58 return 059 if not config.format:60 config.format = [config.default_format]61 elif config.format and "format" in config.defaults:62 # -- CASE: Formatter are specified in behave configuration file.63 # Check if formatter are provided on command-line, too.64 if len(config.format) == len(config.defaults["format"]):65 # -- NO FORMATTER on command-line: Add default formatter.66 config.format.append(config.default_format)67 if "help" in config.format:68 print_formatters("Available formatters:")69 return 070 if len(config.outputs) > len(config.format):71 print("CONFIG-ERROR: More outfiles (%d) than formatters (%d)." % \72 (len(config.outputs), len(config.format)))73 return 174 # -- MAIN PART:75 failed = True76 try:77 reset_runtime()78 runner = runner_class(config)79 failed = runner.run()80 except ParserError as e:81 print(u"ParserError: %s" % e)82 except ConfigError as e:83 print(u"ConfigError: %s" % e)84 except FileNotFoundError as e:85 print(u"FileNotFoundError: %s" % e)86 except InvalidFileLocationError as e:87 print(u"InvalidFileLocationError: %s" % e)88 except InvalidFilenameError as e:89 print(u"InvalidFilenameError: %s" % e)90 except ConstraintError as e:91 print(u"ConstraintError: %s" % e)92 except Exception as e:93 # -- DIAGNOSTICS:94 text = _text(e)95 print(u"Exception %s: %s" % (e.__class__.__name__, text))96 raise97 if config.show_snippets and runner.undefined_steps:98 print_undefined_step_snippets(runner.undefined_steps,99 colored=config.color)100 return_code = 0101 if failed:102 return_code = 1103 return return_code104# ---------------------------------------------------------------------------105# MAIN SUPPORT FOR: run_behave()106# ---------------------------------------------------------------------------107def print_language_list(stream=None):108 """Print list of supported languages, like:109 * English110 * French111 * German112 * ...113 """114 from behave.i18n import languages115 if stream is None:116 stream = sys.stdout117 if six.PY2:118 # -- PYTHON2: Overcome implicit encode problems (encoding=ASCII).119 stream = codecs.getwriter("UTF-8")(sys.stdout)120 iso_codes = languages.keys()121 print("Languages available:")122 for iso_code in sorted(iso_codes):123 native = languages[iso_code]["native"]124 name = languages[iso_code]["name"]125 print(u" %s: %s / %s" % (iso_code, native, name), file=stream)126 return 0127def print_language_help(config, stream=None):128 from behave.i18n import languages129 if stream is None:130 stream = sys.stdout131 if six.PY2:132 # -- PYTHON2: Overcome implicit encode problems (encoding=ASCII).133 stream = codecs.getwriter("UTF-8")(sys.stdout)134 if config.lang_help not in languages:135 print("%s is not a recognised language: try --lang-list" % \136 config.lang_help, file=stream)137 return 1138 trans = languages[config.lang_help]139 print(u"Translations for %s / %s" % (trans["name"],140 trans["native"]), file=stream)141 for kw in trans:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!