Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _loadTestsFromTestClass(self, event, cls):
# ... fire event for others to load from
evt = LoadFromTestClassEvent(event.loader, cls)
result = self.session.hooks.loadTestsFromTestClass(evt)
if evt.handled:
loaded_suite = result or event.loader.suiteClass()
else:
names = self._getTestMethodNames(event, cls)
try:
loaded_suite = event.loader.suiteClass(
[util.transplant_class(
MethodTestCase(cls), cls.__module__)(name)
for name in names])
except:
return event.loader.suiteClass(
event.loader.failedLoadTests(cls.__name__, sys.exc_info()))
if evt.extraTests:
loaded_suite.addTests(evt.extraTests)
# ... add extra tests
return loaded_suite
except (AttributeError, ImportError):
event.handled = True
return event.loader.failedLoadTests(name, sys.exc_info())
if result is None:
return
parent, obj, name, index = result
if isinstance(obj, type) and not issubclass(obj, unittest.TestCase):
# name is a test case class
event.extraTests.append(self._loadTestsFromTestClass(event, obj))
elif (isinstance(parent, type) and
not issubclass(parent, unittest.TestCase) and
not util.isgenerator(obj) and
not hasattr(obj, 'paramList')):
# name is a single test method
event.extraTests.append(
util.transplant_class(
MethodTestCase(parent), parent.__module__)(obj.__name__))
def createTest(name):
return util.transplant_class(
GeneratorFunctionCase, obj.__module__)(name, **args)
for test in self._testsFromGenerator(event, name, extras, createTest):
def _generateFuncTests(self, obj):
args = {}
setUp = getattr(obj, 'setUp', None)
tearDown = getattr(obj, 'tearDown', None)
if setUp is not None:
args['setUp'] = setUp
if tearDown is not None:
args['tearDown'] = tearDown
for index, argSet in enumerate_params(obj.paramList):
def func(argSet=argSet, obj=obj):
return obj(*argSet)
func = functools.update_wrapper(func, obj)
delattr(func, 'paramList')
name = '%s.%s' % (obj.__module__, obj.__name__)
func_name = util.name_from_args(name, index, argSet)
yield util.transplant_class(
ParamsFunctionCase, obj.__module__)(func_name, func, **args)
tests = []
args = {}
setUp = getattr(obj, 'setUp', None)
tearDown = getattr(obj, 'tearDown', None)
if setUp is not None:
args['setUp'] = setUp
if tearDown is not None:
args['tearDown'] = tearDown
paramList = getattr(obj, 'paramList', None)
isGenerator = util.isgenerator(obj)
if paramList is not None or isGenerator:
return tests
else:
case = util.transplant_class(
unittest.FunctionTestCase, obj.__module__)(obj, **args)
tests.append(case)
return tests