MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _parametrize_cls

Function _parametrize_cls

lib/sqlalchemy/testing/plugin/pytestplugin.py:406–436  ·  view source on GitHub ↗

implement a class-based version of pytest parametrize.

(module, cls)

Source from the content-addressed store, hash-verified

404
405
406def _parametrize_cls(module, cls):
407 """implement a class-based version of pytest parametrize."""
408
409 if "_sa_parametrize" not in cls.__dict__:
410 return [cls]
411
412 _sa_parametrize = cls._sa_parametrize
413 classes = []
414 for full_param_set in itertools.product(
415 *[params for argname, params in _sa_parametrize]
416 ):
417 cls_variables = {}
418
419 for argname, param in zip(
420 [_sa_param[0] for _sa_param in _sa_parametrize], full_param_set
421 ):
422 if not argname:
423 raise TypeError("need argnames for class-based combinations")
424 argname_split = re.split(r",\s*", argname)
425 for arg, val in zip(argname_split, param.values):
426 cls_variables[arg] = val
427 parametrized_name = "_".join(
428 re.sub(r"\W", "", token)
429 for param in full_param_set
430 for token in param.id.split("-")
431 )
432 name = "%s_%s" % (cls.__name__, parametrized_name)
433 newcls = type.__new__(type, name, (cls,), cls_variables)
434 setattr(module, name, newcls)
435 classes.append(newcls)
436 return classes
437
438
439_current_class = None

Callers 1

Calls 4

subMethod · 0.80
joinMethod · 0.45
__new__Method · 0.45
appendMethod · 0.45

Tested by

no test coverage detected