mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
split ate/main.py to ate/cli.py and ate/task.py
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
|||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import HtmlTestRunner
|
||||||
|
|
||||||
|
from ate.task import create_task
|
||||||
|
|
||||||
|
def main():
|
||||||
|
""" parse command line options and run commands.
|
||||||
|
"""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='Api Test Engine.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--testcase-path', default='testcases',
|
||||||
|
help="testcase file path")
|
||||||
|
parser.add_argument(
|
||||||
|
'--log-level', default='INFO',
|
||||||
|
help="Specify logging level, default is INFO.")
|
||||||
|
parser.add_argument(
|
||||||
|
'--report-name',
|
||||||
|
help="Specify report name, default is generated time.")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
log_level = getattr(logging, args.log_level.upper())
|
||||||
|
logging.basicConfig(level=log_level)
|
||||||
|
|
||||||
|
testcase_path = args.testcase_path.rstrip('/')
|
||||||
|
task_suite = create_task(testcase_path)
|
||||||
|
|
||||||
|
output_folder_name = os.path.basename(os.path.splitext(testcase_path)[0])
|
||||||
|
kwargs = {
|
||||||
|
"output": output_folder_name,
|
||||||
|
"report_name": args.report_name
|
||||||
|
}
|
||||||
|
HtmlTestRunner.HTMLTestRunner(**kwargs).run(task_suite)
|
||||||
@@ -1,10 +1,5 @@
|
|||||||
import os
|
|
||||||
import argparse
|
|
||||||
import logging
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import HtmlTestRunner
|
|
||||||
|
|
||||||
from ate import runner, utils
|
from ate import runner, utils
|
||||||
|
|
||||||
|
|
||||||
@@ -56,33 +51,3 @@ def create_task(testcase_path):
|
|||||||
task_suite.addTest(suite)
|
task_suite.addTest(suite)
|
||||||
|
|
||||||
return task_suite
|
return task_suite
|
||||||
|
|
||||||
def main():
|
|
||||||
""" parse command line options and run commands.
|
|
||||||
"""
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description='Api Test Engine.')
|
|
||||||
parser.add_argument(
|
|
||||||
'--testcase-path', default='testcases',
|
|
||||||
help="testcase file path")
|
|
||||||
parser.add_argument(
|
|
||||||
'--log-level', default='INFO',
|
|
||||||
help="Specify logging level, default is INFO.")
|
|
||||||
parser.add_argument(
|
|
||||||
'--report-name',
|
|
||||||
help="Specify report name, default is generated time.")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
log_level = getattr(logging, args.log_level.upper())
|
|
||||||
logging.basicConfig(level=log_level)
|
|
||||||
|
|
||||||
testcase_path = args.testcase_path.rstrip('/')
|
|
||||||
task_suite = create_task(testcase_path)
|
|
||||||
|
|
||||||
output_folder_name = os.path.basename(os.path.splitext(testcase_path)[0])
|
|
||||||
kwargs = {
|
|
||||||
"output": output_folder_name,
|
|
||||||
"report_name": args.report_name
|
|
||||||
}
|
|
||||||
HtmlTestRunner.HTMLTestRunner(**kwargs).run(task_suite)
|
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
from ate.main import main
|
from ate.cli import main
|
||||||
main()
|
main()
|
||||||
@@ -2,7 +2,7 @@ import os
|
|||||||
import random
|
import random
|
||||||
import requests
|
import requests
|
||||||
from test.base import ApiServerUnittest
|
from test.base import ApiServerUnittest
|
||||||
from ate import main, utils
|
from ate import task, utils
|
||||||
|
|
||||||
class TestMain(ApiServerUnittest):
|
class TestMain(ApiServerUnittest):
|
||||||
|
|
||||||
@@ -16,15 +16,15 @@ class TestMain(ApiServerUnittest):
|
|||||||
def test_create_suite(self):
|
def test_create_suite(self):
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.yml')
|
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.yml')
|
||||||
testsets = utils.load_testcases_by_path(testcase_file_path)
|
testsets = utils.load_testcases_by_path(testcase_file_path)
|
||||||
suite = main.create_suite(testsets[0])
|
suite = task.create_suite(testsets[0])
|
||||||
self.assertEqual(suite.countTestCases(), 2)
|
self.assertEqual(suite.countTestCases(), 2)
|
||||||
for testcase in suite:
|
for testcase in suite:
|
||||||
self.assertIsInstance(testcase, main.ApiTestCase)
|
self.assertIsInstance(testcase, task.ApiTestCase)
|
||||||
|
|
||||||
def test_create_task(self):
|
def test_create_task(self):
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.yml')
|
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.yml')
|
||||||
task_suite = main.create_task(testcase_file_path)
|
task_suite = task.create_task(testcase_file_path)
|
||||||
self.assertEqual(task_suite.countTestCases(), 2)
|
self.assertEqual(task_suite.countTestCases(), 2)
|
||||||
for suite in task_suite:
|
for suite in task_suite:
|
||||||
for testcase in suite:
|
for testcase in suite:
|
||||||
self.assertIsInstance(testcase, main.ApiTestCase)
|
self.assertIsInstance(testcase, task.ApiTestCase)
|
||||||
Reference in New Issue
Block a user