def __call__(self, fn):
def _preparer_wrapper(test_class_instance, **kwargs):
self.live_test = not isinstance(test_class_instance, ReplayableTest)
self.test_class_instance = test_class_instance
if self.live_test or test_class_instance.in_recording:
resource_name = self.random_name
if not self.live_test and isinstance(self, RecordingProcessor):
test_class_instance.recording_processors.append(self)
else:
resource_name = self.moniker
with self.override_disable_recording():
parameter_update = self.create_resource(
resource_name,
**kwargs
)
test_class_instance.addCleanup(
lambda: self.remove_resource_with_record_override(resource_name, **kwargs)
)
if parameter_update:
kwargs.update(parameter_update)
if not is_preparer_func(fn):
# the next function is the actual test function. the kwargs need to be trimmed so
# that parameters which are not required will not be passed to it.
args, _, kw, _ = inspect.getargspec(fn) # pylint: disable=deprecated-method
if kw is None:
args = set(args)
for key in [k for k in kwargs if k not in args]:
del kwargs[key]
fn(test_class_instance, **kwargs)
setattr(_preparer_wrapper, '__is_preparer', True)
functools.update_wrapper(_preparer_wrapper, fn)
return _preparer_wrapper
评论列表
文章目录