Best Python code snippet using hypothesis
coverage.py
Source:coverage.py
...44IN_COVERAGE_TESTS = os.getenv('HYPOTHESIS_INTERNAL_COVERAGE') == 'true'45if IN_COVERAGE_TESTS:46 log = open('branch-check', 'w')47 written = set()48 def record_branch(name, value):49 key = (name, value)50 if key in written:51 return52 written.add(key)53 log.write(54 json.dumps({'name': name, 'value': value})55 )56 log.write('\n')57 log.flush()58 description_stack = []59 @contextmanager60 def check_block(name, depth):61 # We add an extra two callers to the stack: One for the contextmanager62 # function, one for our actual caller, so we want to go two extra63 # stack frames up.64 caller = sys._getframe(depth + 2)65 local_description = '%s at %s:%d' % (66 name,67 pretty_file_name(caller.f_code.co_filename),68 caller.f_lineno,69 )70 try:71 description_stack.append(local_description)72 description = ' in '.join(reversed(description_stack)) + ' passed'73 yield74 record_branch(description, True)75 except:76 record_branch(description, False)77 raise78 finally:79 description_stack.pop()80 @contextmanager81 def check(name):82 with check_block(name, 2):83 yield84 def check_function(f):85 @proxies(f)86 def accept(*args, **kwargs):87 # depth of 2 because of the proxy function calling us.88 with check_block(f.__name__, 2):89 return f(*args, **kwargs)90 return accept...
branchcheck.py
Source:branchcheck.py
...42 return result43if os.getenv('HYPOTHESIS_INTERNAL_BRANCH_CHECK') == 'true':44 log = open('branch-check', 'w')45 written = set()46 def record_branch(name, value):47 key = (name, value)48 if key in written:49 return50 written.add(key)51 log.write(52 json.dumps({'name': name, 'value': value})53 )54 log.write('\n')55 log.flush()56 def check_function(f):57 @proxies(f)58 def accept(*args, **kwargs):59 # 0 is here, 1 is the proxy function, 2 is where we were actually60 # called from.61 caller = sys._getframe(2)62 description = '%s:%d, %s passed' % (63 pretty_file_name(caller.f_code.co_filename),64 caller.f_lineno, f.__name__,65 )66 try:67 result = f(*args, **kwargs)68 record_branch(description, True)69 return result70 except:71 record_branch(description, False)72 raise73 return accept74else:75 def check_function(f):...
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!!