Best Python code snippet using lemoncheesecake
builder.py
Source:builder.py
...147 """148 return InjectedFixture(fixture_name)149def _default_naming_scheme(name, description, parameters, nb):150 return name + "_%d" % nb, description + " #%d" % nb151def _format_naming_scheme(name_fmt, description_fmt):152 def naming_scheme(_, __, parameters, ___):153 return name_fmt.format(**parameters), description_fmt.format(**parameters)154 return naming_scheme155class _Parametrized(object):156 def __init__(self, parameters_source, naming_scheme):157 self._parameters_source = parameters_source158 self.naming_scheme = naming_scheme159 @property160 def parameters_source(self):161 source = iter(self._parameters_source)162 try:163 first_item = next(source)164 except StopIteration:165 return166 if type(first_item) is dict:167 yield first_item168 for item in source:169 yield item170 else:171 if type(first_item) in STRING_TYPES:172 names = [s.strip() for s in first_item.split(",")]173 else:174 names = first_item # assume list or tuple175 for values in source:176 yield dict(zip(names, values))177def parametrized(parameter_source, naming_scheme=_default_naming_scheme):178 # type: (Iterable, Optional[Union[Callable[[str, str, dict, int], Tuple[str, str]], Sequence]]) -> Any179 """180 Decorator, make the test parametrized.181 :param parameter_source: it can be either:182 - an iterable of dicts, each dict representing the arguments passed to the test183 - a CSV-like mode, where the first element of the list represents the argument names as an str or a sequence184 (example: ``"i,j"`` or ``("i", "j")``) and the remaining elements are sequences of the arguments to be185 passed to the test.186 :param naming_scheme: optional, it can be either:187 - a optional function that takes as parameters the base test name, description, parameters, index188 and must return the expanded test name and description as a two elements list189 - a tuple/list of two (name + description) format strings, example: ``("test_{i}_plus_{j}", "Test {i} plus {j}")``190 """191 def wrapper(obj):192 md = get_metadata(obj)193 md.parametrized = _Parametrized(194 parameter_source,195 naming_scheme if callable(naming_scheme) else _format_naming_scheme(*naming_scheme)196 )197 return obj...
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!!