How to use print_attachments method in stestr

Best Python code snippet using stestr_python

subunit_trace.py

Source:subunit_trace.py Github

copy

Full Screen

...72 if tag.startswith('worker-'):73 return int(tag[7:])74 return 075# Print out stdout/stderr if it exists, always76def print_attachments(stream, test, all_channels=False):77 """Print out subunit attachments.78 Print out subunit attachments that contain content. This79 runs in 2 modes, one for successes where we print out just stdout80 and stderr, and an override that dumps all the attachments.81 """82 channels = ('stdout', 'stderr')83 for name, detail in test['details'].items():84 # NOTE(sdague): the subunit names are a little crazy, and actually85 # are in the form pythonlogging:'' (with the colon and quotes)86 name = name.split(':')[0]87 if detail.content_type.type == 'test':88 detail.content_type.type = 'text'89 if (all_channels or name in channels) and detail.as_text():90 title = "Captured %s:" % name91 stream.write("\n%s\n%s\n" % (title, ('~' * len(title))))92 # indent attachment lines 4 spaces to make them visually93 # offset94 for line in detail.as_text().split('\n'):95 stream.write(" %s\n" % line)96def show_outcome(stream, test, print_failures=False, failonly=False):97 global RESULTS98 status = test['status']99 # TODO(sdague): ask lifeless why on this?100 if status == 'exists':101 return102 worker = find_worker(test)103 name = cleanup_test_name(test['id'])104 duration = get_duration(test['timestamps'])105 if worker not in RESULTS:106 RESULTS[worker] = []107 RESULTS[worker].append(test)108 # don't count the end of the return code as a fail109 if name == 'process-returncode':110 return111 if status == 'fail':112 FAILS.append(test)113 stream.write('{%s} %s [%s] ... FAILED\n' % (114 worker, name, duration))115 if not print_failures:116 print_attachments(stream, test, all_channels=True)117 elif not failonly:118 if status == 'success':119 stream.write('{%s} %s [%s] ... ok\n' % (120 worker, name, duration))121 print_attachments(stream, test)122 elif status == 'skip':123 stream.write('{%s} %s ... SKIPPED: %s\n' % (124 worker, name, test['details']['reason'].as_text()))125 else:126 stream.write('{%s} %s [%s] ... %s\n' % (127 worker, name, duration, test['status']))128 if not print_failures:129 print_attachments(stream, test, all_channels=True)130 stream.flush()131def print_fails(stream):132 """Print summary failure report.133 Currently unused, however there remains debate on inline vs. at end134 reporting, so leave the utility function for later use.135 """136 if not FAILS:137 return138 stream.write("\n==============================\n")139 stream.write("Failed %s tests - output below:" % len(FAILS))140 stream.write("\n==============================\n")141 for f in FAILS:142 stream.write("\n%s\n" % f['id'])143 stream.write("%s\n" % ('-' * len(f['id'])))144 print_attachments(stream, f, all_channels=True)145 stream.write('\n')146def count_tests(key, value):147 count = 0148 for k, v in RESULTS.items():149 for item in v:150 if key in item:151 if re.search(value, item[key]):152 count += 1153 return count154def run_time():155 runtime = 0.0156 for k, v in RESULTS.items():157 for test in v:158 runtime += float(get_duration(test['timestamps']).strip('s'))...

Full Screen

Full Screen

subunit-trace.py

Source:subunit-trace.py Github

copy

Full Screen

...61 if tag.startswith('worker-'):62 return int(tag[7:])63 return 'NaN'64# Print out stdout/stderr if it exists, always65def print_attachments(stream, test, all_channels=False):66 """Print out subunit attachments.67 Print out subunit attachments that contain content. This68 runs in 2 modes, one for successes where we print out just stdout69 and stderr, and an override that dumps all the attachments.70 """71 channels = ('stdout', 'stderr')72 for name, detail in test['details'].items():73 # NOTE(sdague): the subunit names are a little crazy, and actually74 # are in the form pythonlogging:'' (with the colon and quotes)75 name = name.split(':')[0]76 if detail.content_type.type == 'test':77 detail.content_type.type = 'text'78 if (all_channels or name in channels) and detail.as_text():79 title = "Captured %s:" % name80 stream.write("\n%s\n%s\n" % (title, ('~' * len(title))))81 # indent attachment lines 4 spaces to make them visually82 # offset83 for line in detail.as_text().split('\n'):84 stream.write(" %s\n" % line)85def show_outcome(stream, test, print_failures=False):86 global RESULTS87 status = test['status']88 # TODO(sdague): ask lifeless why on this?89 if status == 'exists':90 return91 worker = find_worker(test)92 name = cleanup_test_name(test['id'])93 duration = get_duration(test['timestamps'])94 if worker not in RESULTS:95 RESULTS[worker] = []96 RESULTS[worker].append(test)97 # don't count the end of the return code as a fail98 if name == 'process-returncode':99 return100 if status == 'success':101 stream.write('{%s} %s [%s] ... ok\n' % (102 worker, name, duration))103 print_attachments(stream, test)104 elif status == 'fail':105 FAILS.append(test)106 stream.write('{%s} %s [%s] ... FAILED\n' % (107 worker, name, duration))108 if not print_failures:109 print_attachments(stream, test, all_channels=True)110 elif status == 'skip':111 stream.write('{%s} %s ... SKIPPED: %s\n' % (112 worker, name, test['details']['reason'].as_text()))113 else:114 stream.write('{%s} %s [%s] ... %s\n' % (115 worker, name, duration, test['status']))116 if not print_failures:117 print_attachments(stream, test, all_channels=True)118 stream.flush()119def print_fails(stream):120 """Print summary failure report.121 Currently unused, however there remains debate on inline vs. at end122 reporting, so leave the utility function for later use.123 """124 if not FAILS:125 return126 stream.write("\n==============================\n")127 stream.write("Failed %s tests - output below:" % len(FAILS))128 stream.write("\n==============================\n")129 for f in FAILS:130 stream.write("\n%s\n" % f['id'])131 stream.write("%s\n" % ('-' * len(f['id'])))132 print_attachments(stream, f, all_channels=True)133 stream.write('\n')134def count_tests(key, value):135 count = 0136 for k, v in RESULTS.items():137 for item in v:138 if key in item:139 if re.search(value, item[key]):140 count += 1141 return count142def run_time():143 runtime = 0.0144 for k, v in RESULTS.items():145 for test in v:146 runtime += float(get_duration(test['timestamps']).strip('s'))...

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 stestr 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