Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def loadTestsFromName(self, event):
"""Load tests from event.name if it names a test case/method"""
name = event.name
module = event.module
log.debug("load %s from %s", name, module)
try:
result = util.test_from_name(name, module)
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 issubclass(obj, unittest.TestCase):
# name is a test case class
event.extraTests.append(self._loadTestsFromTestCase(event, obj))
elif (isinstance(parent, type) and
issubclass(parent, unittest.TestCase) and
not util.isgenerator(obj) and
not hasattr(obj, 'paramList')):
# name is a single test method
event.extraTests.append(parent(obj.__name__))
def loadTestsFromName(self, event):
"""Load tests from event.name if it names a test class/method"""
name = event.name
module = event.module
try:
result = util.test_from_name(name, module)
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(
def loadTestsFromName(self, event):
"""Load parameterized test named on command line"""
original_name = name = event.name
module = event.module
try:
result = util.test_from_name(name, module)
except (AttributeError, ImportError):
event.handled = True
return event.loader.failedLoadTests(name, sys.exc_info())
if result is None:
# we can't find it - let the default case handle it
return
parent, obj, fqname, index = result
if not hasattr(obj, 'paramList'):
return
if (index is None and not
isinstance(parent, type) and not
isinstance(obj, types.FunctionType)):
log.debug(
"Don't know how to load parameterized tests from %s", obj)
def loadTestsFromName(self, event):
"""Load test if event.name is the name of a test function"""
name = event.name
module = event.module
try:
result = util.test_from_name(name, module)
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, types.FunctionType) and not
util.isgenerator(obj) and not
hasattr(obj, 'paramList') and
util.num_expected_args(obj) == 0):
suite = event.loader.suiteClass()
suite.addTests(self._createTests(obj))
event.handled = True
return suite
def loadTestsFromName(self, event):
"""Load tests from generator named on command line"""
original_name = name = event.name
module = event.module
try:
result = util.test_from_name(name, module)
except (AttributeError, ImportError):
event.handled = True
return event.loader.failedLoadTests(name, sys.exc_info())
if result is None:
# we can't find it - let the default case handle it
return
parent, obj, name, index = result
if not util.isgenerator(obj):
return
if (index is None and not
isinstance(parent, type) and not
isinstance(obj, types.FunctionType)):
log.debug("Don't know how to load generator tests from %s", obj)
return