def display_slowest_setups(self, stream): """Prints a report regarding the slowest setUp/tearDown times.""" table = prettytable.PrettyTable(["Elapsed", "File", "Method"]) table.align["File"] = "l" table.align["Method"] = "l" stream.writeln("Per setup breakdown") slowest_tests = SetupTime.get_slowest_tests(10) for row in slowest_tests: table.add_row( [ "{:.05f}s".format(row["elapsed"]), row["file"], "{}.{}.{}".format(row["module"], row["class"], row["func"]), ] ) stream.writeln(table.get_string()) stream.writeln() stream.writeln("Per file breakdown") table = prettytable.PrettyTable(["Elapsed", "File"]) table.align["File"] = "l" # Display the slowest test files slowest_files = SetupTime.get_slowest_files(10) for row in slowest_files: table.add_row(["{:.05f}s".format(row["sum_elapsed"]), row["file"]]) stream.writeln(table.get_string()) # Display the total time spent in tests stream.writeln() stream.writeln("*** Total setup time: {:.05f}s".format(SetupTime.get_total_time()))
def display_slowest_setups(self, stream): """Prints a report regarding the slowest setUp/tearDown times.""" table = prettytable.PrettyTable(['Elapsed', 'File', 'Method']) table.align['File'] = 'l' table.align['Method'] = 'l' stream.writeln('Per setup breakdown') slowest_tests = SetupTime.get_slowest_tests(10) for row in slowest_tests: table.add_row(['{:.05f}s'.format(row['elapsed']), row['file'], '{}.{}.{}'.format( row['module'], row['class'], row['func'])]) stream.writeln(table.get_string()) stream.writeln() stream.writeln('Per file breakdown') table = prettytable.PrettyTable(['Elapsed', 'File']) table.align['File'] = 'l' # Display the slowest test files slowest_files = SetupTime.get_slowest_files(10) for row in slowest_files: table.add_row(['{:.05f}s'.format(row['sum_elapsed']), row['file']]) stream.writeln(table.get_string()) # Display the total time spent in tests stream.writeln() stream.writeln('*** Total setup time: {:.05f}s'.format(SetupTime.get_total_time()))
def write(cls, html_file): """Writes the HTML report to the given file.""" f = open(html_file, 'w') f.write('<html>') f.write('<head>') f.write('</head>') f.write('<body>') f.write('<h1>Test times</h1>') fmt_test = '<tr><td>{:.05f}</td><td>{}</td></tr><tr><td> </td><td>{}</td></tr>' f.write('<table>') f.write('<tr><th>Time</th><th>Test info</th></tr>') for row in TestTime.get_slowest_tests(10): f.write( fmt_test.format( row['elapsed'], row['file'], '{}.{}.{}'.format(row['module'], row['class'], row['func']))) f.write('</table>') fmt_file = '<tr><td>{:.05f}</td><td>{}</td></tr>' f.write('<table>') f.write('<tr><th>Time</th><th>Test info</th></tr>') for row in TestTime.get_slowest_files(10): f.write(fmt_file.format(row['sum_elapsed'], row['file'])) f.write('</table>') f.write('<h1>Setup times</h1>') f.write('<table>') f.write('<tr><th>Time</th><th>Test info</th></tr>') for row in SetupTime.get_slowest_tests(10): f.write( fmt_test.format( row['elapsed'], row['file'], '{}.{}.{}'.format(row['module'], row['class'], row['func']))) f.write('</table>') f.write('<table>') f.write('<tr><th>Time</th><th>Test info</th></tr>') for row in SetupTime.get_slowest_files(10): f.write(fmt_file.format(row['sum_elapsed'], row['file'])) f.write('</table>') f.write('</body>') f.write('</html>') f.close()
def write(cls, html_file): """Writes the HTML report to the given file.""" f = open(html_file, 'w') f.write('<html>') f.write('<head>') f.write('</head>') f.write('<body>') f.write('<h1>Test times</h1>') fmt_test = '<tr><td>{:.05f}</td><td>{}</td></tr><tr><td> </td><td>{}</td></tr>' f.write('<table>') f.write('<tr><th>Time</th><th>Test info</th></tr>') for row in TestTime.get_slowest_tests(10): f.write(fmt_test.format(row['elapsed'], row['file'], '{}.{}.{}'.format(row['module'], row['class'], row['func']))) f.write('</table>') fmt_file = '<tr><td>{:.05f}</td><td>{}</td></tr>' f.write('<table>') f.write('<tr><th>Time</th><th>Test info</th></tr>') for row in TestTime.get_slowest_files(10): f.write(fmt_file.format(row['sum_elapsed'], row['file'])) f.write('</table>') f.write('<h1>Setup times</h1>') f.write('<table>') f.write('<tr><th>Time</th><th>Test info</th></tr>') for row in SetupTime.get_slowest_tests(10): f.write(fmt_test.format(row['elapsed'], row['file'], '{}.{}.{}'.format(row['module'], row['class'], row['func']))) f.write('</table>') f.write('<table>') f.write('<tr><th>Time</th><th>Test info</th></tr>') for row in SetupTime.get_slowest_files(10): f.write(fmt_file.format(row['sum_elapsed'], row['file'])) f.write('</table>') f.write('</body>') f.write('</html>') f.close()