Commit 74105883 authored by huangqiang's avatar huangqiang

修复bug

parent 92419cf5
...@@ -4,7 +4,5 @@ report/ ...@@ -4,7 +4,5 @@ report/
temp temp
*.har *.har
*.xml *.xml
#script/base_api
test/ test/
__pycache__/ */__pycache__/
#download_file_temp/ \ No newline at end of file
\ No newline at end of file
...@@ -2,8 +2,17 @@ ...@@ -2,8 +2,17 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ceb24b37-65a1-4b3f-be3f-7040ebc4079d" name="默认变更列表" comment=""> <list default="true" id="ceb24b37-65a1-4b3f-be3f-7040ebc4079d" name="默认变更列表" comment="">
<change afterPath="$PROJECT_DIR$/run_cmd.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/common/common_config.py" beforeDir="false" afterPath="$PROJECT_DIR$/common/common_config.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/common/connect_db.py" beforeDir="false" afterPath="$PROJECT_DIR$/common/connect_db.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/common/operation_excel.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/log/2021_06_04_run.log" beforeDir="false" afterPath="$PROJECT_DIR$/log/2021_06_04_run.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/run.py" beforeDir="false" afterPath="$PROJECT_DIR$/run.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/script/conftest.py" beforeDir="false" afterPath="$PROJECT_DIR$/script/conftest.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/views/case_run_view.py" beforeDir="false" afterPath="$PROJECT_DIR$/views/case_run_view.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -49,7 +58,7 @@ ...@@ -49,7 +58,7 @@
</key> </key>
</component> </component>
<component name="RunManager" selected="Python.service_start"> <component name="RunManager" selected="Python.service_start">
<configuration name="basic_parameter_set_data" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="debug" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="jk_interface_test" /> <module name="jk_interface_test" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
...@@ -57,11 +66,11 @@ ...@@ -57,11 +66,11 @@
<env name="PYTHONUNBUFFERED" value="1" /> <env name="PYTHONUNBUFFERED" value="1" />
</envs> </envs>
<option name="SDK_HOME" value="" /> <option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/script/ji_yun_ying_pc/system_set/data_config" /> <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test" />
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/script/ji_yun_ying_pc/system_set/data_config/basic_parameter_set_data.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/test/debug.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
...@@ -70,7 +79,7 @@ ...@@ -70,7 +79,7 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="date_data" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="run" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="jk_interface_test" /> <module name="jk_interface_test" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
...@@ -78,11 +87,11 @@ ...@@ -78,11 +87,11 @@
<env name="PYTHONUNBUFFERED" value="1" /> <env name="PYTHONUNBUFFERED" value="1" />
</envs> </envs>
<option name="SDK_HOME" value="" /> <option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/script/global_data_config" /> <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/script/global_data_config/date_data.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/run.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
...@@ -91,7 +100,7 @@ ...@@ -91,7 +100,7 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="run" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="run_cmd" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="jk_interface_test" /> <module name="jk_interface_test" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
...@@ -103,7 +112,7 @@ ...@@ -103,7 +112,7 @@
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/run.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/run_cmd.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="EMULATE_TERMINAL" value="false" />
...@@ -133,34 +142,29 @@ ...@@ -133,34 +142,29 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="url_to_method" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="debug.py 中的 pytest" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<module name="jk_interface_test" /> <module name="jk_interface_test" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" /> <option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/tools" /> <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/test" />
<option name="IS_MODULE_SDK" value="true" /> <option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/tools/url_to_method.py" /> <option name="_new_keywords" value="&quot;&quot;" />
<option name="PARAMETERS" value="" /> <option name="_new_parameters" value="&quot;&quot;" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="_new_additionalArguments" value="&quot;&quot;" />
<option name="EMULATE_TERMINAL" value="false" /> <option name="_new_target" value="&quot;$PROJECT_DIR$/test/debug.py&quot;" />
<option name="MODULE_MODE" value="false" /> <option name="_new_targetType" value="&quot;PATH&quot;" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.service_start" /> <item itemvalue="Python.service_start" />
<item itemvalue="Python.debug" />
<item itemvalue="Python 测试.debug.py 中的 pytest" />
<item itemvalue="Python.run_cmd" />
<item itemvalue="Python.run" /> <item itemvalue="Python.run" />
<item itemvalue="Python.basic_parameter_set_data" />
<item itemvalue="Python.url_to_method" />
<item itemvalue="Python.date_data" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
......
...@@ -27,6 +27,13 @@ common_config = { ...@@ -27,6 +27,13 @@ common_config = {
"host": 'host_name', # 服务器地址 "host": 'host_name', # 服务器地址
"port": 3306, # 端口 "port": 3306, # 端口
"send_receive_timeout": 60 # 超时时间 "send_receive_timeout": 60 # 超时时间
},
"report_db": {
'database': 'test_service',
"user": 'root',
"password": '123456',
"host": '192.168.32.50',
"port": 3307
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import psycopg2 import psycopg2
import pymongo import pymongo
import pymysql import pymysql
import datetime
from clickhouse_driver import Client from clickhouse_driver import Client
from common.common_config import common_config from common.common_config import common_config
import pandas as pd import pandas as pd
...@@ -39,9 +40,9 @@ class OperationDb: ...@@ -39,9 +40,9 @@ class OperationDb:
# 创建连接对象 # 创建连接对象
with psycopg2.connect(**common_config.get("db_config")) as conn: with psycopg2.connect(**common_config.get("db_config")) as conn:
with conn.cursor() as cur: with conn.cursor() as cur:
cur.execute(sql_str) result = cur.execute(sql_str)
conn.commit() conn.commit()
return True return result
class OperationMysqlDb: class OperationMysqlDb:
...@@ -58,27 +59,36 @@ class OperationMysqlDb: ...@@ -58,27 +59,36 @@ class OperationMysqlDb:
@staticmethod @staticmethod
def query_sql(sql_str): def query_sql(sql_str):
# 创建连接对象 # 创建连接对象
with pymysql.connect(**common_config.get("mysql_db_config")) as conn: conn = pymysql.connect(**common_config.get("mysql_db_config"))
try:
with conn.cursor() as cur: with conn.cursor() as cur:
cur.execute(sql_str) cur.execute(sql_str)
results = cur.fetchall() results = cur.fetchall()
return results return results
except Exception as e:
conn.close()
@staticmethod @staticmethod
def pd_query_sql(sql_str) -> pd.DataFrame: def pd_query_sql(sql_str) -> pd.DataFrame:
# 创建连接对象 # 创建连接对象
with pymysql.connect(**common_config.get("mysql_db_config")) as conn: conn = pymysql.connect(**common_config.get("mysql_db_config"))
try:
results = pd.read_sql(sql_str, conn) results = pd.read_sql(sql_str, conn)
return results return results
except Exception as e:
conn.close()
@staticmethod @staticmethod
def insert_update_delete_sql(sql_str): def insert_update_delete_sql(sql_str):
# 创建连接对象 # 创建连接对象
with pymysql.connect(**common_config.get("mysql_db_config")) as conn: conn = pymysql.connect(**common_config.get("mysql_db_config"))
try:
with conn.cursor() as cur: with conn.cursor() as cur:
cur.execute(sql_str) result = cur.execute(sql_str)
conn.commit() conn.commit()
return True return result
except Exception as e:
conn.close()
class OperationClickHouseDb: class OperationClickHouseDb:
...@@ -137,6 +147,39 @@ class OperationMongoDb: ...@@ -137,6 +147,39 @@ class OperationMongoDb:
# print(x) # print(x)
class OperationReportDb:
@staticmethod
def query_sql(sql_str):
# 创建连接对象
conn = pymysql.connect(**common_config.get("report_db"))
try:
with conn.cursor() as cur:
cur.execute(sql_str)
results = cur.fetchall()
return results
except Exception as e:
conn.close()
@staticmethod
def insert_update_delete_sql(sql_str):
print(sql_str)
# 创建连接对象
conn = pymysql.connect(**common_config.get("report_db"))
try:
with conn.cursor() as cur:
result = cur.execute(sql_str)
conn.commit()
return result
except Exception as e:
conn.close()
@classmethod
def update_report_result(cls, dir_id, result="", status=2):
record_sql = f"""update test_service.interface_test_report set result={result}, update_time='{datetime.datetime.now()}', status={status} where dir_id={dir_id}"""
cls.insert_update_delete_sql(record_sql)
if __name__ == "__main__": if __name__ == "__main__":
"""pip install psycopg2-binary""" """pip install psycopg2-binary"""
sql = """select student_id,student_name from service_profile.student limit 10""" sql = """select student_id,student_name from service_profile.student limit 10"""
......
# coding:utf-8
import xlrd
import xlwt
from xlutils.copy import copy
import os
class OperationExcel:
def __init__(self, file_name, sheet_name):
if file_name:
self.file_name = file_name
self.sheet_name = sheet_name
else:
print("excel的路径和sheetname不能为空", file_name, sheet_name)
# 获取sheets的内容
def get_sheet(self):
data = xlrd.open_workbook(self.file_name, encoding_override="utf-8")
tables = data.sheet_by_name(self.sheet_name)
return tables
# 获取单元格的行数
def get_lines(self):
tables = self.get_sheet()
return tables.nrows
# 获取某一个单元格的内容
def get_cell_value(self, row, col):
return self.get_sheet().cell_value(row, col)
# 根据data,列号,找到找到对应行的内容
def get_row_datas(self, data, col_id):
row_nums = self.get_row_num(data, col_id)
rows_datas = self.get_row_values(row_nums)
return rows_datas
# 根据对应的1个内容找到对应的行号
def get_row_num(self, data, col_id):
nums = []
num = 0
cols_data = self.get_cols_data(col_id)
for col_data in cols_data:
if data == col_data:
nums.append(num)
num = num + 1
return nums
# 根据行号,找到该行的内容
def get_row_values(self, row_nums):
tables = self.get_sheet()
row_datas = []
for num in row_nums:
row_data = tables.row_values(num)
row_datas.append(row_data)
return row_datas
# 获取某一列的内容
def get_cols_data(self, col_id):
if col_id:
cols = self.get_sheet().col_values(col_id)
else:
cols = self.get_sheet().col_values(0)
return cols
if __name__ == '__main__':
pass
# opers = OperationExcel()
# print(opers.get_cell_value(1, 2))
...@@ -96,3 +96,29 @@ AttributeError: 'NoneType' object has no attribute 'startswith' ...@@ -96,3 +96,29 @@ AttributeError: 'NoneType' object has no attribute 'startswith'
[2021-06-04 17:46:34,777] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}' [2021-06-04 17:46:34,777] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 17:49:30,810] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}' [2021-06-04 17:49:30,810] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 17:56:10,548] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}' [2021-06-04 17:56:10,548] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:30:30,733] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:30:40,373] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:37:03,178] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:39:27,843] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:40:20,408] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:43:01,059] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:43:09,389] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:43:18,473] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:45:22,490] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:45:30,809] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:50:06,863] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:50:51,289] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:52:21,394] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:54:10,787] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 19:59:09,933] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:00:53,802] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:01:02,073] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:09:48,360] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:09:57,425] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:10:03,273] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:11:51,972] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet::"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:11:52,322] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet::"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:14:00,602] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet",\n "script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestCanContinueGrade"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:18:25,061] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet",\n "script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestCanContinueGrade"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:18:33,123] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet",\n "script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestCanContinueGrade"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-04 20:19:24,322] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{ "case_path_list":["script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet",\n "script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestCanContinueGrade"],\n "host": "http://192.168.32.36",\n "account_group": "A",\n "db_config": "36"\n}'
[2021-06-05 17:40:41,209] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 7, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": null, "reruns_delay": null}}'
[2021-06-05 17:50:52,841] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 8, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": null, "reruns_delay": null}}'
[2021-06-05 17:52:17,048] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 9, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": null, "reruns_delay": null}}'
[2021-06-05 17:53:18,121] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 10, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": null, "reruns_delay": null}}'
[2021-06-05 17:54:10,122] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 11, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": null, "reruns_delay": null}}'
[2021-06-05 17:54:54,042] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 12, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": null, "reruns_delay": null}}'
[2021-06-05 18:19:09,191] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 17, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": null, "reruns_delay": null}}'
[2021-06-05 19:31:26,488] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 18, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": 0, "reruns_delay": 0}}'
[2021-06-05 19:32:17,267] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 19, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": 0, "reruns_delay": 0}}'
[2021-06-05 19:39:38,826] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 20, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": 0, "reruns_delay": 0}}'
[2021-06-05 19:39:59,386] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 21, "case_path_list": null, "cmd_config": {"host": null, "account_group": null, "pg_db": null, "mongo_db": null, "mysql_db": null, "click_house_db": null, "reruns": 0, "reruns_delay": 0}}'
[2021-06-05 19:48:41,057] __init__.py->wrapper line:16 [INFO] <class 'views.case_run_view.TestCaseRunHandler'>接收到的参数:b'{"record_id": 22, "case_path_list": ["./script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py"], "cmd_config": {"host": "http://192.168.32.36", "account_group": null, "pg_db": "36", "mongo_db": "36", "mysql_db": "36", "click_house_db": "36", "reruns": 0, "reruns_delay": 0}}'
...@@ -20,4 +20,5 @@ pandas~=1.2.4 ...@@ -20,4 +20,5 @@ pandas~=1.2.4
datacompy~=0.7.2 datacompy~=0.7.2
numpy~=1.20.2 numpy~=1.20.2
PyYAML~=5.4.1 PyYAML~=5.4.1
tornado~=6.1 tornado~=6.1
\ No newline at end of file clickhouse-driver
\ No newline at end of file
...@@ -42,13 +42,8 @@ class RunTest: ...@@ -42,13 +42,8 @@ class RunTest:
"--click_house_db", self.click_house_db_config, "--click_house_db", self.click_house_db_config,
*other_cmd *other_cmd
] ]
print(run_config)
return pytest.main(run_config) return pytest.main(run_config)
def run(self, other_cmd: list = []):
self.run_test(other_cmd=other_cmd)
self.generate_allure_report()
def collection_case(self): def collection_case(self):
run_config = [ run_config = [
*self.case_path_list, *self.case_path_list,
......
import os
import datetime
from common.operation_time import GetTime
from common.connect_db import OperationReportDb
# def generate_execute_record(custom_id, user_name=None, suite_id=None, suite_name=None, create_time=None):
# record_sql = f"""insert into test_service.execute_record(custom_id, user_name, suite_id, suite_name, create_time)
# values ({custom_id}, '{user_name}', {suite_id}, '{suite_name}', '{create_time}')"""
# OperationReportDb.insert_update_delete_sql(record_sql)
def generate_report(record_id, dir_id=None, report_path=None, account_group=None, create_time=None):
record_sql = f"""insert into test_service.interface_test_report(record_id, dir_id, report_path, account_group, create_time, status)
values ({record_id}, {dir_id}, '{report_path}', '{account_group}', '{create_time}', 1)"""
OperationReportDb.insert_update_delete_sql(record_sql)
def update_report(dir_id, status):
record_sql = f"""update test_service.interface_test_report set update_time='{datetime.datetime.now()}', status={status} where dir_id={dir_id}"""
OperationReportDb.insert_update_delete_sql(record_sql)
def run_cmd(record_id, case_path_list, cmd_config: dict):
case_path = " ".join(case_path_list)
allure_path = "./allure-2.13.8/bin/allure"
host = cmd_config.get("host", "http://192.168.32.36")
account_group = cmd_config.get("account_group", "A")
pg_db = cmd_config.get("pg_db", "36")
mongo_db = cmd_config.get("mongo_db", "36")
mysql_db = cmd_config.get("mysql_db", "36")
click_house_db = cmd_config.get("click_house_db", "36")
reruns = cmd_config.get("reruns")
reruns_delay = cmd_config.get("reruns_delay", 1)
path_dir_id = GetTime.get_current_time().get("current_time_num")
allure_report_xml_path = f"./report/{path_dir_id}/xml"
allure_report_html_path = f"./report/{path_dir_id}/html"
report_html_uri = f"/{path_dir_id}/html/index.html"
generate_report(record_id, dir_id=path_dir_id, report_path=report_html_uri, account_group=account_group, create_time=datetime.datetime.now())
normal_cmd = f"pytest -q {case_path} --host={host} --account={account_group} --alluredir={allure_report_xml_path} --dir_id={path_dir_id}"
db_cmd = f"--db={pg_db} --mongo_db={mongo_db} --mysql_db={mysql_db} --click_house_db={click_house_db}"
if reruns:
rerun_cmd = f"--reruns={reruns} --reruns-delay={reruns_delay}"
else:
rerun_cmd = ""
os.system(f"{normal_cmd} {db_cmd} {rerun_cmd}")
os.system(f"{allure_path} generate {allure_report_xml_path} -o {allure_report_html_path} --clean")
update_report(path_dir_id, 3)
if __name__ == '__main__':
case_path_list = [
"./script/ji_yun_ying_pc/system_set/test_basic_parameter_set.py::TestFullClassTargetSet",
# "./script/ding_ding_jdata/person_time/test_person_time.py::TestsPersonTimeDetail::test_detail_page_search_date",
# "./script/ding_ding_jdata/person_time/test_person_time.py::TestsPersonTimeDetail::test_detail_page_search_target",
# "./script/ding_ding_jdata/person_time/test_person_time.py::TestsPersonTimeDetail::test_detail_page_search_subject",
]
config = {
# host = "https://geek.jkwljy.com"
# account_group = "线上"
"host": "http://192.168.32.36",
"account_group": "A",
"pg_db": "36",
"mongo_db": "36"
}
run_cmd(9, case_path_list, config)
import pytest import pytest
import jsonpath import jsonpath
from _pytest.config import ExitCode, Config
from _pytest.terminal import TerminalReporter
import time
from common.connect_db import OperationReportDb
from script import default_header from script import default_header
from common.common_config import common_config from common.common_config import common_config
from script.db_config import db_configs from script.db_config import db_configs
...@@ -8,6 +13,7 @@ from script.defalut_account import accounts ...@@ -8,6 +13,7 @@ from script.defalut_account import accounts
from script.base_api.service_user.wxMini import wxMini_auth_post from script.base_api.service_user.wxMini import wxMini_auth_post
# 自定义命令行参数
def pytest_addoption(parser): def pytest_addoption(parser):
# 注册一个命令行选项host # 注册一个命令行选项host
# parser.addoption("--host", default="http://172.10.62.94", dest="env", help="set test run env") # parser.addoption("--host", default="http://172.10.62.94", dest="env", help="set test run env")
...@@ -22,8 +28,11 @@ def pytest_addoption(parser): ...@@ -22,8 +28,11 @@ def pytest_addoption(parser):
parser.addoption("--click_house_db", default="36", dest="click_house_db", help="set test click_house_db") parser.addoption("--click_house_db", default="36", dest="click_house_db", help="set test click_house_db")
# 注册一个命令行选项account # 注册一个命令行选项account
parser.addoption("--account", default="A", dest="account", help="set run default account group") parser.addoption("--account", default="A", dest="account", help="set run default account group")
# 注册一个命令行选项account
parser.addoption("--dir_id", default=0, dest="dir_id", help="报告的目录ID")
# 会话开始前执行
def pytest_sessionstart(session): def pytest_sessionstart(session):
# 初始化测试数据库配置 # 初始化测试数据库配置
common_config["db_config"] = db_configs.get(session.config.getoption('--db')) common_config["db_config"] = db_configs.get(session.config.getoption('--db'))
...@@ -32,6 +41,32 @@ def pytest_sessionstart(session): ...@@ -32,6 +41,32 @@ def pytest_sessionstart(session):
common_config["click_house_db_config"] = db_configs.get(session.config.getoption('--click_house_db')) common_config["click_house_db_config"] = db_configs.get(session.config.getoption('--click_house_db'))
def pytest_terminal_summary(terminalreporter: TerminalReporter, exitstatus: ExitCode, config: Config):
'''收集测试结果'''
# print(terminalreporter.stats)
# failed = len([i for i in terminalreporter.stats.get('failed', []) if i.when != 'teardown'])
# error = len([i for i in terminalreporter.stats.get('error', []) if i.when != 'teardown'])
# skipped = len([i for i in terminalreporter.stats.get('skipped', []) if i.when != 'teardown'])
duration = time.time() - terminalreporter._sessionstarttime
total = terminalreporter._numcollected
passed = len([i for i in terminalreporter.stats.get('passed', []) if i.when != 'teardown'])
if total > 0:
success_rate = "%.2f" % ((passed / total) * 100) + '%'
else:
success_rate = "-"
# terminalreporter._sessionstarttime 会话开始时间
duration = time.time() - terminalreporter._sessionstarttime
dir_id = config.getoption('--dir_id')
if dir_id:
if success_rate == "100.00%":
OperationReportDb.update_report_result(dir_id, result="通过", status=2)
else:
OperationReportDb.update_report_result(dir_id, result="失败", status=2)
# 获取收集的用例 # 获取收集的用例
# def pytest_collection_modifyitems(session, config, items): # def pytest_collection_modifyitems(session, config, items):
# all_test = [] # all_test = []
......
...@@ -3,7 +3,7 @@ import json ...@@ -3,7 +3,7 @@ import json
import os import os
from views import exception_catch from views import exception_catch
from views import my_thread_pool from views import my_thread_pool
from run import RunTest from run_cmd import run_cmd
class TestCaseRunHandler(RequestHandler): class TestCaseRunHandler(RequestHandler):
...@@ -11,13 +11,11 @@ class TestCaseRunHandler(RequestHandler): ...@@ -11,13 +11,11 @@ class TestCaseRunHandler(RequestHandler):
@exception_catch() @exception_catch()
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
body = json.loads(self.request.body) body = json.loads(self.request.body)
record_id = body.get("record_id")
case_path_list = body.get("case_path_list") case_path_list = body.get("case_path_list")
host = body.get("host") cmd_config = body.get("cmd_config")
account_group = body.get("account_group")
db_config = body.get("db_config")
if case_path_list: if case_path_list:
run_test = RunTest(case_path_list, host=host, account_group=account_group, db_config=db_config) my_thread_pool.submit(run_cmd, record_id, case_path_list, cmd_config)
my_thread_pool.submit(run_test.run())
res = {"code": 0, "data": None, "msg": "用例已在后台运行请稍后查看报告"} res = {"code": 0, "data": None, "msg": "用例已在后台运行请稍后查看报告"}
else: else:
res = {"code": 101, "data": None, "msg": "用例列表不能为空"} res = {"code": 101, "data": None, "msg": "用例列表不能为空"}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment