How to use _format_test_method_name method in Testify

Best Python code snippet using Testify_python

test_logger.py

Source:test_logger.py Github

copy

Full Screen

...86 def report_failure(self, result):87 pass88 def report_stats(self, test_case_count, all_results, failed_results, unknown_results):89 pass90 def _format_test_method_name(self, test_method):91 """Take a test method as input and return a string for output"""92 if test_method['module'] != '__main__':93 return "%s %s.%s" % (test_method['module'], test_method['class'], test_method['name'])94 else:95 return "%s.%s" % (test_method['class'], test_method['name'])96class TextTestLogger(TestLoggerBase):97 def __init__(self, options, stream=sys.stdout):98 super(TextTestLogger, self).__init__(options, stream)99 # Checking for color support isn't as fun as we might hope. We're100 # going to use the command 'tput colors' to get a list of colors101 # supported by the shell. But of course we if this fails terribly,102 # we'll want to just fall back to no colors103 self.use_color = False104 # if TERM is not present in environ, tput prints to stderr105 # if tput's stderr is a pipe, it lies.106 if sys.stdin.isatty() and 'TERM' in os.environ:107 try:108 output = subprocess.check_output(('tput', 'colors'))109 if int(output.strip()) >= 8:110 self.use_color = True111 except Exception as e:112 if self.options.verbosity >= VERBOSITY_VERBOSE:113 self.writeln("Failed to find color support: %r" % e)114 def write(self, message):115 """Write a message to the output stream, no trailing newline"""116 if six.PY2:117 self.stream.write(message.encode('UTF-8') if isinstance(message, six.text_type) else message)118 else:119 self.stream.write(message.decode('UTF-8') if isinstance(message, bytes) else message)120 self.stream.flush()121 def writeln(self, message):122 """Write a message and append a newline"""123 self.write(message)124 self.write('\n')125 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(30, 38)126 def _colorize(self, message, color=CYAN):127 if not color or not self.use_color:128 return message129 else:130 start_color = '\033[1;%sm' % color131 end_color = '\033[m'132 return start_color + message + end_color133 def test_discovery_failure(self, exc):134 self.writeln(self._colorize("DISCOVERY FAILURE!", self.MAGENTA))135 self.writeln("There was a problem importing one or more tests:")136 self.writeln(str(exc))137 def report_test_name(self, test_method):138 if self.options.verbosity >= VERBOSITY_VERBOSE:139 self.write("%s ... " % self._format_test_method_name(test_method))140 def report_test_result(self, result):141 if self.options.verbosity > VERBOSITY_SILENT:142 if result['success']:143 if result['previous_run']:144 status = "flaky"145 else:146 status = "success"147 elif result['failure']:148 status = "fail"149 elif result['error']:150 status = "error"151 elif result['interrupted']:152 status = "interrupted"153 else:154 status = "unknown"155 status_description, status_letter, color = {156 "success": ('ok', '.', self.GREEN),157 "flaky": ('flaky', '!', self.YELLOW),158 "fail": ('FAIL', 'F', self.RED),159 "error": ('ERROR', 'E', self.RED),160 "interrupted": ('INTERRUPTED', '-', self.YELLOW),161 "unknown": ('UNKNOWN', '?', None),162 }[status]163 if status in ('fail', 'error'):164 self.writeln("\n%s: %s\n%s" % (status, self._format_test_method_name(result['method']), result['exception_info']))165 if self.options.verbosity == VERBOSITY_NORMAL:166 self.write(self._colorize(status_letter, color))167 elif result['normalized_run_time']:168 self.writeln("%s in %s" % (self._colorize(status_description, color), result['normalized_run_time']))169 else:170 self.writeln(self._colorize(status_description, color))171 def heading(self, *messages):172 self.writeln("")173 self.writeln("=" * 72)174 for line in messages:175 self.writeln(line)176 def failure(self, result):177 self.writeln("")178 self.writeln("=" * 72)179 self.writeln(self._format_test_method_name(result['method']))180 if self.use_color:181 self.writeln(result['exception_info_pretty'])182 else:183 self.writeln(result['exception_info'])184 self.writeln('=' * 72)185 self.writeln("")186 def report_stats(self, test_case_count, **results):187 successful = results.get('successful', [])188 failed = results.get('failed', [])189 interrupted = results.get('interrupted', [])190 unknown = results.get('unknown', [])191 test_method_count = sum(len(bucket) for bucket in results.values())192 test_word = "test" if test_method_count == 1 else "tests"193 case_word = "case" if test_case_count == 1 else "cases"...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful