Commit 3cdc4811 by jiaqiying

根据传入的产品名来运行对应产品的测试用例

parent 13cae9ed
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import json import json
import logging import logging
import requests import requests
from config import BaseConfig from config import BaseConfig, BMCConfig
def request_main(url, headers, method, data): def request_main(url, headers, method, data):
...@@ -28,4 +28,11 @@ def request_main(url, headers, method, data): ...@@ -28,4 +28,11 @@ def request_main(url, headers, method, data):
if res != None: if res != None:
return res.json() return res.json()
return res return res
\ No newline at end of file
def get_case_dir(product_name):
test_case_dir = BaseConfig.default_test_case_dir
if product_name == BMCConfig.name:
test_case_dir = BMCConfig.test_case_dir
return test_case_dir
\ No newline at end of file
...@@ -5,12 +5,15 @@ class BaseConfig(): ...@@ -5,12 +5,15 @@ class BaseConfig():
# 请求头 # 请求头
headers = {'Content-Type': 'application/json; charset=utf-8'} headers = {'Content-Type': 'application/json; charset=utf-8'}
# 当前运行的产品名 # 当前运行的产品名
current_product = "" current_product = "bmc"
default_test_case_dir = "test_case/bmc/"
class BMCConfig(BaseConfig): class BMCConfig(BaseConfig):
"""斑马信用app的配置类""" """斑马信用app的配置类"""
pass # 测试用例目录
name = "bmc"
test_case_dir = "test_case/bmc/"
class DingTalk(BaseConfig): class DingTalk(BaseConfig):
......
#coding:utf-8 #coding:utf-8
import os import os
import pytest import pytest
import argparse
from config import BaseConfig
from common.tools import get_case_dir
def get_parser():
parser = argparse.ArgumentParser(description="Demo of argparse")
parser.add_argument('--product', type=str, default=BaseConfig.current_product)
return parser
if __name__ == "__main__": if __name__ == "__main__":
parser = get_parser()
args = get_parser()
# 获取要执行的产品的用例目录
test_case_dir = get_case_dir(args.product)
#删除之前报告
for one in os.listdir('../report/tmp'): for one in os.listdir('../report/tmp'):
if 'json' in one: if 'json' in one:
os.remove(f'../report/tmp/{one}') os.remove(f'../report/tmp/{one}')
# 生成报告数据 # 生成报告数据
pytest.main([ '-s', '--alluredir', '../report/tmp']) pytest.main(['-v', '-s', test_case_dir, '--alluredir', '../report/tmp'])
# 打开报告 # 打开报告
os.system('allure serve ../report/tmp') os.system('allure serve ../report/tmp')
\ No newline at end of file
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