本文整理汇总了Python中unittest.result.TestResult类的典型用法代码示例。如果您正苦于以下问题:Python TestResult类的具体用法?Python TestResult怎么用?Python TestResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run_test
def run_test(test: TestCase, result: TestResult) -> bool:
failed = False
test_method = get_test_method(test)
if fast_tests_only() and is_known_slow_test(test_method):
return failed
test_name = full_test_name(test)
bounce_key_prefix_for_testing(test_name)
bounce_redis_key_prefix_for_testing(test_name)
flush_caches_for_testing()
if not hasattr(test, "_pre_setup"):
msg = "Test doesn't have _pre_setup; something is wrong."
error_pre_setup = (Exception, Exception(msg), None) # type: Tuple[Any, Any, Any]
result.addError(test, error_pre_setup)
return True
test._pre_setup()
start_time = time.time()
test(result) # unittest will handle skipping, error, failure and success.
delay = time.time() - start_time
enforce_timely_test_completion(test_method, test_name, delay, result)
slowness_reason = getattr(test_method, 'slowness_reason', '')
TEST_TIMINGS.append((delay, test_name, slowness_reason))
test._post_teardown()
return failed
开发者ID:joydeep1701,项目名称:zulip,代码行数:32,代码来源:test_runner.py
示例2: _execute_test
def _execute_test(cls, test: FirmwareTestClass, router: Router, routers: List[Router]) -> TestResult:
if not isinstance(router, Router):
raise ValueError("Chosen Router is not a real Router...")
# proofed: this method runs in other process as the server
setproctitle(str(router.id) + " - " + str(test))
logging.debug("%sExecute test " + str(test) + " on Router(" + str(router.id) + ")", LoggerSetup.get_log_deep(2))
test_suite = defaultTestLoader.loadTestsFromTestCase(test)
# prepare all test cases
for test_case in test_suite:
logging.debug("%sTestCase " + str(test_case), LoggerSetup.get_log_deep(4))
test_case.prepare(router, routers)
result = TestResult()
cls.__setns(router)
try:
result = test_suite.run(result)
except Exception as e:
logging.error("%sTestCase execution raised an exception", LoggerSetup.get_log_deep(3))
logging.error("%s" + str(e), LoggerSetup.get_log_deep(3))
test_obj = test()
result.addError(test_obj, sys.exc_info()) # add the reason of the exception
finally:
# I'm sry for this dirty hack, but if you don't do this you get an
# "TypeError: cannot serialize '_io.TextIOWrapper' object" because sys.stdout is not serializeable...
result._original_stdout = None
result._original_stderr = None
logging.debug("%sResult from test " + str(result), LoggerSetup.get_log_deep(3))
return result
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:35,代码来源:server.py
示例3: addSuccess
def addSuccess(self, test):
self.result["success_count"] += 1
self.result["class_list"][self.class_name]["success_count"] += 1
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["status"] = SUCCESS
TestResult.addSuccess(self, test)
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["message"] = self.silence_output()
开发者ID:Ozahata,项目名称:pddoctest,代码行数:8,代码来源:result.py
示例4: addUnexpectedSuccess
def addUnexpectedSuccess(self, test):
self.result["unexpected_success_count"] += 1
self.result["class_list"][self.class_name]["unexpected_success_count"] \
+= 1
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["status"] = UNEXPECTED_SUCCESS
TestResult.addUnexpectedSuccess(self, test)
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["message"] = self.silence_output()
开发者ID:Ozahata,项目名称:pddoctest,代码行数:9,代码来源:result.py
示例5: addSkip
def addSkip(self, test, reason):
self.result["skip_count"] += 1
self.result["class_list"][self.class_name]["skip_count"] += 1
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["status"] = SKIP
TestResult.addSkip(self, test, reason)
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["message"] = self.silence_output()
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["error"] = reason
开发者ID:Ozahata,项目名称:pddoctest,代码行数:10,代码来源:result.py
示例6: addFailure
def addFailure(self, test, err):
self.result["failure_count"] += 1
self.result["class_list"][self.class_name]["failure_count"] += 1
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["status"] = FAILURE
TestResult.addFailure(self, test, err)
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["message"] = self.silence_output()
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["error"] = self.failures[-1][1]
开发者ID:Ozahata,项目名称:pddoctest,代码行数:10,代码来源:result.py
示例7: addError
def addError(self, test, err):
self.result["error_count"] += 1
self.result["class_list"][self.class_name]["error_count"] += 1
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["status"] = ERROR
TestResult.addError(self, test, err)
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["message"] = self.silence_output()
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["error"] = self.errors[-1][1]
开发者ID:Ozahata,项目名称:pddoctest,代码行数:10,代码来源:result.py
示例8: enforce_timely_test_completion
def enforce_timely_test_completion(test_method: Any, test_name: str,
delay: float, result: TestResult) -> None:
if hasattr(test_method, 'slowness_reason'):
max_delay = 2.0 # seconds
else:
max_delay = 0.4 # seconds
if delay > max_delay:
msg = '** Test is TOO slow: %s (%.3f s)\n' % (test_name, delay)
result.addInfo(test_method, msg)
开发者ID:joydeep1701,项目名称:zulip,代码行数:10,代码来源:test_runner.py
示例9: _wait_for_test_done
def _wait_for_test_done(cls, test: FirmwareTestClass, router: Router, done_event: DoneEvent) -> None:
"""
Wait 2 minutes until the test is done.
Handles the result from the tests.
Triggers the next job/test.
:param test: test to execute
:param router: the Router
:param done_event: event which will be triggered when the task is finished
"""
logging.debug("%sWait for test" + str(test), LoggerSetup.get_log_deep(2))
try:
async_result = cls._task_pool.apply_async(func=cls._execute_test, args=(test, router, cls._routers))
result = async_result.get(120) # wait 2 minutes or raise an TimeoutError
logging.debug("%sTest done " + str(test), LoggerSetup.get_log_deep(1))
logging.debug("%sFrom Router(" + str(router.id) + ")", LoggerSetup.get_log_deep(2))
cls._test_results.append((router.id, str(test), result))
try:
length = len(cls._test_results)
t = cls._test_results[(length - 1)]
cls.write_in_db(str(length), t)
except Exception as e:
logging.error("Error at write test results into DB: {0}".format(e))
except Exception as e:
logging.error("%sTest raised an Exception: " + str(e), LoggerSetup.get_log_deep(1))
result = TestResult()
result._original_stdout = None
result._original_stderr = None
cls._test_results.append((router.id, str(test), result))
cls._task_errors.append((router.id, sys.exc_info()))
try:
length = len(cls._test_results)
t = cls._test_results[(length - 1)]
cls.write_in_db(str(length), t)
except Exception as e:
logging.error("Error at write test results into DB: {0}".format(e))
finally:
cls.set_running_task(router, None)
# logging.debug(str(cls._test_results))
# start next test in the queue
done_event.set()
cls.__start_task(router, None)
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:49,代码来源:server.py
示例10: startTest
def startTest(self, test):
"""
Starting the test we redirect the output to not show in the screen
"""
TestResult.startTest(self, test)
# Start a new output text result
self.output = StringIO()
self._stdout.fp = self.output
self._stderr.fp = self.output
# Conserve the original output
self.org_stderr = sys.stderr
self.org_stdout = sys.stdout
sys.stdout = self._stdout
sys.stderr = self._stderr
# Define the structure
self.class_name = test.__class__.__name__
self.method_name = test._testMethodName
if self.class_name not in self.result["class_list"].keys():
class_doc = [] if test.__doc__ is None else \
[ item.strip() for item in test.__doc__.splitlines() \
if item.strip() != "" ]
self.result["class_list"][self.class_name] = {
"module": test.__module__,
"description": class_doc,
"success_count": 0,
"error_count": 0,
"failure_count": 0,
"skip_count": 0,
"expected_failure_count": 0,
"unexpected_success_count": 0,
"methods": {}
}
if self.method_name not in \
self.result["class_list"][self.class_name]["methods"].keys():
method_doc = [""] if test._testMethodDoc is None else \
[ item.strip() for item in \
test._testMethodDoc.splitlines() if item.strip() != ""
]
self.result["class_list"][self.class_name]["methods"][self.method_name] = \
{
"started": datetime.now(),
"status": None,
"stopped": None,
"message": "",
"error": None,
"description": method_doc
}
开发者ID:Ozahata,项目名称:pddoctest,代码行数:47,代码来源:result.py
示例11: __init__
def __init__(self, stream=None, descriptions=None, verbosity=None):
self.result = {
"success_count": 0,
"error_count": 0,
"failure_count": 0,
"skip_count": 0,
"expected_failure_count": 0,
"unexpected_success_count": 0,
"class_list": {},
}
TestResult.__init__(self, stream=stream, descriptions=descriptions,
verbosity=verbosity)
self._stderr = StandardDevice(sys.stderr)
self._stdout = StandardDevice(sys.stdout)
self.org_stderr = None
self.org_stdout = None
self.stream = stream
self.verbosity = verbosity
开发者ID:Ozahata,项目名称:pddoctest,代码行数:18,代码来源:result.py
示例12: run
def run(self, result: TestResult, debug: Optional[bool]=False) -> TestResult:
"""
This function mostly contains the code from
unittest.TestSuite.run. The need to override this function
occurred because we use run_test to run the testcase.
"""
topLevel = False
if getattr(result, '_testRunEntered', False) is False:
result._testRunEntered = topLevel = True
for test in self:
# but this is correct. Taken from unittest.
if result.shouldStop:
break
if isinstance(test, TestSuite):
test.run(result, debug=debug)
else:
self._tearDownPreviousClass(test, result) # type: ignore
self._handleModuleFixture(test, result) # type: ignore
self._handleClassSetUp(test, result) # type: ignore
result._previousTestClass = test.__class__
if (getattr(test.__class__, '_classSetupFailed', False) or
getattr(result, '_moduleSetUpFailed', False)):
continue
failed = run_test(test, result)
if failed or result.shouldStop:
result.shouldStop = True
break
if topLevel:
self._tearDownPreviousClass(None, result) # type: ignore
self._handleModuleTearDown(result) # type: ignore
result._testRunEntered = False
return result
开发者ID:joydeep1701,项目名称:zulip,代码行数:36,代码来源:test_runner.py
示例13: addError
def addError(self, *args, **kwargs):
# type: (*Any, **Any) -> None
TestResult.addError(self, *args, **kwargs)
开发者ID:aakash-cr7,项目名称:zulip,代码行数:3,代码来源:test_runner.py
示例14: addSkip
def addSkip(self, test: TestCase, reason: Text) -> None:
TestResult.addSkip(self, test, reason)
self.stream.writeln("** Skipping {}: {}".format(full_test_name(test),
reason))
self.stream.flush()
开发者ID:joydeep1701,项目名称:zulip,代码行数:5,代码来源:test_runner.py
示例15: addSuccess
def addSuccess(self, *args: Any, **kwargs: Any) -> None:
TestResult.addSuccess(self, *args, **kwargs)
开发者ID:joydeep1701,项目名称:zulip,代码行数:2,代码来源:test_runner.py
示例16: addFailure
def addFailure(self, *args: Any, **kwargs: Any) -> None:
TestResult.addFailure(self, *args, **kwargs)
test_name = full_test_name(args[0])
self.failed_tests.append(test_name)
开发者ID:joydeep1701,项目名称:zulip,代码行数:4,代码来源:test_runner.py
示例17: stopTest
def stopTest(self, test):
self.silence_output()
self.result["class_list"][self.class_name]["methods"][self.method_name]\
["stopped"] = datetime.now()
TestResult.stopTest(self, test)
开发者ID:Ozahata,项目名称:pddoctest,代码行数:5,代码来源:result.py
示例18: startTest
def startTest(self, test: TestCase) -> None:
TestResult.startTest(self, test)
self.stream.writeln("Running {}".format(full_test_name(test)))
self.stream.flush()
开发者ID:joydeep1701,项目名称:zulip,代码行数:4,代码来源:test_runner.py
示例19: addError
def addError(self, *args, **kwargs):
# type: (*Any, **Any) -> None
TestResult.addError(self, *args, **kwargs)
test_name = full_test_name(args[0])
self.failed_tests.append(test_name)
开发者ID:christi3k,项目名称:zulip,代码行数:5,代码来源:test_runner.py
示例20: addSuccess
def addSuccess(self, *args, **kwargs):
# type: (*Any, **Any) -> None
TestResult.addSuccess(self, *args, **kwargs)
开发者ID:christi3k,项目名称:zulip,代码行数:3,代码来源:test_runner.py
注:本文中的unittest.result.TestResult类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论