[pytest]
addopts= -vs ./testcase/test_import_order.py
testpaths= ./testcase
python_files= test_*.py
python_classes=Test*
python_functions=test_*
markers=
login
order
smoke
@pytest.mark.login
@pytest.mark.run(order=1)
def test_login(self,browser_fixture):
conftest.py
@pytest.fixture(scope='class',params=[url])
def browser_fixture(request):
driver = webdriver.Chrome()
driver.get(request.param)
print('打开浏览器'+request.param)
yield driver
driver.quit()
print('关闭浏览器')
readexcel.py
from openpyxl import Workbook, load_workbook
class ReadExcel():
# 定义方法:读取指定目录下Excel文件某个sheet单元格的值
def read_excel(filepath,index,x,y):
#wb=Workbook()
wb=load_workbook(filepath)
sheetname=wb.sheetnames[index]
sheet=wb[sheetname]
return sheet.cell(x,y).value
def write_excel(filepath,index,x,y,newstr):
wb = load_workbook(filepath)
sheetname = wb.sheetnames[index]
sheet = wb[sheetname]
sheet.cell(x,y).value=newstr
wb.save(filepath)
readfile.py
class ReadFile:
def get_txtfile(self,filename):
# 获取登录参数
with open(filename, 'r', encoding='utf-8') as loginfile:
login_dict = {}
for loginline in loginfile.readlines():
loginline = loginline.strip()
k = loginline.split(' ')[0]
v = loginline.split(' ')[1]
login_dict[k] = v
loginfile.close()
return login_dict
def get_txtfile1(filename):
# 获取登录参数
with open(filename, 'r', encoding='utf-8') as loginfile:
login_dict = {}
for loginline in loginfile.readlines():
loginline = loginline.strip()
k = loginline.split(' ')[0]
v = loginline.split(' ')[1]
login_dict[k] = v
loginfile.close()
return login_dict
def get_jsonfile(self,filename):
with open(filename,'r',newline='') as file:
lcookie=json.load(file)
file.close()
return lcookie
def get_jsonfile1(filename):
with open(filename,'r',newline='') as file:
lcookie=json.load(file)
file.close()
return lcookie
readyml
def read_yaml():
fileNamePath = os.path.split(os.path.realpath(__file__))[0]
yamlpath = os.path.join(fileNamePath, 'nfig.yaml')
with open(yamlpath,'r',encoding='utf-8') as ymalfile:
conf=ymalfile.read()
mysqlyaml=yaml.load(conf)
#print(mysqlyaml)
return mysqlyaml
https://docs.qameta.io/allure/#_python
|