How to use test_subtest method in hypothesis

Best Python code snippet using hypothesis

fetch.py

Source:fetch.py Github

copy

Full Screen

1import subprocess2import csv3import os4import time5import signal6import tempfile7import multiprocessing8import sys9def run(cmd, timeout, test):10 try:11 timeout = timeout * 10012 result = {}13 result['test'] = test14 outfile = tempfile.NamedTemporaryFile(mode='w+b')15 p = subprocess.Popen(cmd, shell=True, stdout=outfile, stderr=subprocess.STDOUT, preexec_fn=os.setsid, close_fds=True)16 result['curtime'] = time.time()17 result['endtime'] = result['curtime'] + timeout18 sleep_time = 019 finish = False20 while sleep_time < timeout:21 if p.poll() is not None:22 finish = True23 break24 sleep_time += 125 time.sleep(.01)26 result['finish'] = finish27 outfile.seek(0)28 result['output'] = outfile.readlines()29 return result30 except Exception as e:31 print str(e)32 return None33 finally:34 if p is not None and p.poll() is None:35 print 'killing %s' % test36 os.killpg(os.getpgid(p.pid), signal.SIGKILL)37def finish(result):38 try:39 test = result['test']40 if not result['finish']:41 print CRED + "[Hanged ] " + test + CEND42 current_hanged[test] = 143 else:44 reported = False45 count = 146 for output in result['output']:47 tokens = output.split()48 if len(tokens) < 2:49 continue50 # Drop this line so that we get consistent offsets51 if output == "WARNING: no physical memory support, process creation may be slow.\n":52 continue53 if tokens[1].isdigit():54 test_subtest = test + "," + tokens[1]55 count = int(tokens[1]) + 156 else:57 test_subtest = test + "," + str(count)58 count = count + 159 if "TINFO" in output or test_subtest in current_passed or test_subtest in current_failed or test in current_hanged or test_subtest in current_broken:60 continue61 if output:62 output = output.strip()63 print >>f1, output64 if "TFAIL" in output:65 print >>failed_tests_fh, test_subtest66 print CRED + "[Fail ] " + test_subtest + CEND67 current_failed[test_subtest] = 168 reported = True69 elif "TPASS" in output or "PASS:" in output:70 print >>passed_tests_fh, test_subtest71 print CGREEN + "[Pass ] " + test_subtest + CEND72 current_passed[test_subtest] = 173 reported = True74 elif "TCONF" in output or "TBROK" in output or "BROK" in output or "error" in output:75 print >>broken_tests_fh, test_subtest76 # Syscall not implemented or test preparation failed77 print "[Broken(a) ] " + test_subtest + CEND78 current_broken[test_subtest] = 179 reported = True80 if (not reported):81 print >>broken_tests_fh, test82 print CRED + "[Broken(b) ] " + test + CEND83 for output in result['output']:84 print output85 current_broken[test] = 186 except Exception as e:87 print str(e)88CRED = '\033[91m'89CGREEN = '\033[92m'90CEND = '\033[0m'91DEFAULT_TIMEOUT = 3092resultfile = "run_output"93stablePass = "PASSED"94timeouts = "TIMEOUTS"95failed_tests_file = "Failed.csv"96passed_tests_file = "Passed.csv"97broken_tests_file = "Broken.csv"98f1 = open(resultfile, 'w')99failed_tests_fh = open(failed_tests_file, 'w', 0)100passed_tests_fh = open(passed_tests_file, 'w', 0)101broken_tests_fh = open(broken_tests_file, 'w', 0)102failed_tests_fh.write("Test,Subtest number,Status\n")103passed_tests_fh.write("Test,Subtest number\n")104broken_tests_fh.write("Test,Subtest number,Status\n")105current_passed = dict()106current_failed = dict()107current_broken = dict()108current_hanged = dict()109timeouts_dict = dict()110with open(timeouts, 'rb') as csvfile:111 test_timeout = csv.reader(csvfile)112 test_timeout.next()113 for row in test_timeout:114 test = row[0]115 timeout = row[1]116 timeouts_dict[test] = int(timeout)117os.chdir("opt/ltp/testcases/bin")118pool = multiprocessing.Pool()119with open('../../../../syscalls.graphene') as testcases:120 for line in testcases:121 line = line.strip('\r\n\t')122 tokens = line.split( )123 if (tokens[1] == "SGX") :124 test = tokens[2]125 else :126 test = tokens[1]127 if test=="seq":128 test = tokens[6] #splice02129 try: 130 timeout = timeouts_dict[test]131 except KeyError:132 timeout = DEFAULT_TIMEOUT133 pool.apply_async(run, args=([line], timeout, test), callback=finish)134os.chdir("../../../..")135pool.close()136pool.join()137 138stable_passed = dict()139with open(stablePass, 'rb') as csvfile:140 test_subtest = csv.reader(csvfile)141 test_subtest.next()142 for row in test_subtest:143 tst = row[0] + "," + row[1]144 stable_passed[tst] = 1145print "\n\nRESULT [Difference] :\n---------------------\n"146rv = 0147for test in sorted(stable_passed):148 if not test in current_passed:149 print CRED + "Test '" + test + "' did not pass in the current run!!" + CEND150 rv = -1151for test in sorted(current_passed):152 if not test in stable_passed:153 print CGREEN + "Test '" + test + "' passed in the current run!!" + CEND154print "\n"...

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