How to use get_cleanname method in gabbi

Best Python code snippet using gabbi_python

pytester.py

Source:pytester.py Github

copy

Full Screen

...20# Globals storing the test-like functions to be used when starting21# and stopping a suite.22STARTS = {}23STOPS = {}24def get_cleanname(item):25 """Extract a test name from a pytest Function item."""26 if '[' in item.name:27 cleanname = item.name.split('[', 1)[1]28 cleanname = cleanname.split(']', 1)[0]29 return cleanname30 return item.name31def get_suitename(name):32 """Extract a test suite from a clean name.33 This is fragile. It assumes there are no underscores in34 suite names, which is not always true.35 """36 prefix, rest = name.split(':', 1)37 if prefix.startswith('start_') or prefix.startswith('stop_'):38 prefix = prefix.split('_', 1)[1]39 suite = rest.split('_', 1)[0]40 return prefix + ':' + suite41def c_pytest_collection_modifyitems(items, config):42 """Set the starters and stoppers for a limited collection of tests."""43 latest_suite = None44 latest_item = None45 for item in items:46 cleanname = get_cleanname(item)47 if ':' not in cleanname:48 continue49 prefix, testname = cleanname.split('_', 1)50 suitename = get_suitename(cleanname)51 if prefix == 'start' or prefix == 'stop':52 continue53 if latest_suite != suitename:54 item.starter = STARTS[suitename]55 if latest_item:56 latest_item.stopper = STOPS[57 get_suitename(get_cleanname(latest_item))]58 latest_suite = suitename59 latest_item = item60 # Set the last stopper in the list61 if latest_item:62 latest_item.stopper = STOPS[get_suitename(get_cleanname(latest_item))]63def a_pytest_collection_modifyitems(items, config):64 """Traverse collected tests to save START and STOPS.65 Remove those START and STOPS from the tests to run.66 """67 remaining = []68 deselected = []69 for item in items:70 cleanname = get_cleanname(item)71 if ':' not in cleanname:72 remaining.append(item)73 continue74 suitename = get_suitename(cleanname)75 if cleanname.startswith('start_'):76 test = item.callspec.params['test']77 result = item.callspec.params['result']78 # TODO(cdent): Consider a named tuple here79 STARTS[suitename] = (test, result, [])80 deselected.append(item)81 elif cleanname.startswith('stop_'):82 test = item.callspec.params['test']83 STOPS[suitename] = test84 deselected.append(item)...

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