本文整理汇总了Python中unittest.TestLoader.sortTestMethodsUsing方法的典型用法代码示例。如果您正苦于以下问题:Python TestLoader.sortTestMethodsUsing方法的具体用法?Python TestLoader.sortTestMethodsUsing怎么用?Python TestLoader.sortTestMethodsUsing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.TestLoader
的用法示例。
在下文中一共展示了TestLoader.sortTestMethodsUsing方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: terminate_server_process
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import sortTestMethodsUsing [as 别名]
# Ideally this would be in a common helper library shared between the tests
def terminate_server_process(process):
if os.name == "nt":
process.kill()
else:
os.killpg(os.getpgid(process.pid), signal.SIGTERM) # Send the signal to all the process groups
if __name__ == "__main__":
cwd = dirname(realpath(__file__))
print("Current directory is: " + cwd)
server = start_server_process()
try:
runner = TextTestRunner(verbosity=2)
test_loader = TestLoader()
test_loader.sortTestMethodsUsing = sort_test
suite = test_loader.discover(cwd, pattern="*_tests.py")
result = runner.run(suite)
if not result.wasSuccessful():
sys.exit(1)
finally:
print("Killing server")
terminate_server_process(server)
print("Done killing server")
示例2: getResults
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import sortTestMethodsUsing [as 别名]
# Never write output back to the console
self._mirrorOutput = False
unittest.TestResult.stopTest(self, test)
def getResults(self):
return self.results
if __name__ == '__main__':
try:
from test import Test
# Run the tests with our custom setup
loader = TestLoader()
# Maintain the ordering that tests appear in the source code
loader.sortTestMethodsUsing = lambda x, y: -1
tests = loader.loadTestsFromTestCase(Test)
suite = TestSuite([tests])
runner = PrairieTestRunner()
results = runner.run(suite).getResults()
# Compile total number of points
max_points = sum([test['max_points'] for test in results])
earned_points = sum([test['points'] for test in results])
# Assemble final grading results
grading_result = {}
grading_result['tests'] = results
grading_result['score'] = float(earned_points) / float(max_points)
grading_result['succeeded'] = True
print(json.dumps(grading_result, allow_nan=False))