本文整理汇总了Python中unittest.TestCase.__new__方法的典型用法代码示例。如果您正苦于以下问题:Python TestCase.__new__方法的具体用法?Python TestCase.__new__怎么用?Python TestCase.__new__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.TestCase
的用法示例。
在下文中一共展示了TestCase.__new__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import __new__ [as 别名]
def __new__(cls, name=None):
if name is None:
return TestCase.__new__(cls)
from multiprocessing import Process
from multiprocessing import Pipe
parent, child = Pipe()
process = Process(target=run_test, args=SOCKETS + (child, cls, name))
def run(self, result):
process.start()
try:
result.startTest(self)
r = parent.recv()
result.stopTest(self)
if isinstance(r, Exception):
result.addFailure(self, (r.__class__, r, None))
else:
result.failures.extend(r.failures)
result.errors.extend(r.errors)
finally:
process.join()
case = type(cls.__name__, (TestCase,), {
'run': run, '__module__': cls.__module__, name: getattr(cls, name)})
inst = TestCase.__new__(case)
inst.__init__(name)
return inst
示例2: run_test
# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import __new__ [as 别名]
def run_test(stdin, stdout, stderr, pipe, cls, name):
redefine_sockets(stdin, stdout, stderr)
try:
# configure django
from django.conf import settings
settings.configure()
# initialize test case
inst = TestCase.__new__(cls)
inst.__init__(name)
# run test and store result
result = inst.defaultTestResult()
inst.run(result)
# clear test instances dictionary, because it may contain
# values which are local to this process and won't pickle
inst.__dict__.clear()
# reinitialize test case
inst.__init__(name)
try:
pipe.send(result)
except Exception, e:
pipe.send(e)
finally:
redefine_sockets(*SOCKETS)