Pytes是 一个单元测试框架,可以生成html报告。

不要点击:https://item.taobao.com/item.htm?id=613711271112

安装pytest和allure:pip install pytest   :  pip install allure-pytest

pytest生成报告的插件:pip install pytest-html

#卸载
# pip uninstall pytest
#安装
# pip install -U pytest
# 查看
# pytest --version
2、===========================
2、pytest的运行“”(文件名是login.py)

import pytest
import allure
def test_login():
print("正在登录")
if __name__ == "__main__":
pytest.main("-s login.py")
#命令行(用的多,要进入当前文件夹的目录运行保险):pytest -s xxx.py
#如何快速打开当前项目目录?
#控制台下方有一个terminal的打开即可
 3、pytest配置文件ini文件:pytest.ini (必须在同一字执行目录下 )
[pytest]
#添加参数
addopts = -s
#搜索那个文件夹
testpaths = ./app1
#文件
python_files = test_*.py
#类名
python_classes = Test*
#函数名
python_functions = test_*

4、生成测试报告html,命令行输入:pytest --html=report/report.html
生成report文件夹下reporr.htmld报告
修改pytest配置文件:pytest.ini (必须在同一字执行目录下 )
[pytest]
#添加命令参数
addopts = -s --html=report/report.html
#搜索那个文件夹
testpaths = ./scripts
#搜索文件名
python_files =test_*.py
#类名
python_classes = Test*
#函数名
python_functions = test_*

配置文件弄好了就可以在 命令行输入pytest就可以执行所以报告而且自动生成html报告

(用例和报告 文件夹必须分开)

 5、_pycache_出错
只要是复制过来的文件都可能自动生成_pycache_文件,执行pytest时会报错_pycache_
把_pycache_文件删掉即可。
6、控制函数顺序@pytest.mark.run(order=XX)
@pytest.mark.run(order=1)
@pytest.mark.run(order=3)
@pytest.mark.run(order=2)
顺序123.
执行优先级:
0>较小的正数>较大的正数>无标记>较小的负数>较大的负数。如图:

7跳过函数@pytest.mark.skipif(True,reason="done")

(和顺序函数一样,必须先导入 import pytest)

@pytest.mark.skipif(True,reason="done")

8、失败重试10次:在配置文件后面加10

[pytest]
#添加命令参数
addopts = -s --html=report/report.html --reruns 10
#搜索那个文件夹
testpaths = ./scripts
#搜索文件名
python_files =test_*.py
#类名
python_classes = test*
#函数名
python_functions = test_*
如图所示:

9、预期结果:

#写True表示预期是False,假,失败

@pytest.mark.xfail(True,reason="")

#写False表示预期是True,真,成功

@pytest.mark.xfail(False,reason="")

如图:

10、参数化:

keys是参数名,1和2是参数值

@pytest.mark.parametrize("keys",["1","2"])

如图所示:

11、多个参数化

@pytest.mark.parametrize(("username","password"),[("zhangsan","123"),("lisi","456")])

12、封装前置代码:

from appium import webdriver
def int_driver():
    #设置参数
desired_caps = {}
desired_caps['platformName'] = 'Android' # Android系统 or IOS系统
desired_caps['platformVersion'] = '5.1' # Android系统版本
desired_caps['deviceName'] = '1' # (安卓随便写,苹果的写系统的型号)
desired_caps['appPackage'] = 'com.android.settings' # APP夜神模拟器包名
desired_caps['appActivity'] = '.Settings' # APP启动Activity
# 解决中文不能输入问题
desired_caps['unicodeKeyboard'] = True # 每次打开APP不开启重置,否则每次都进入四个欢迎页
desired_caps['resetKeyboard'] = True # 隐藏键盘
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) # 启动APP
return driver
self.driver = init_driver()  #在另一文件里调用此方法
#以下是解决用pytest执行报错的方法:需要导入os 和sys 模块
import os,sys
sys.path.append((os.getcwd()))

12、测试脚本分离技术




 

Pytest安装介绍--使用(html报告)的更多相关文章

  1. Pytest框架介绍

    Pytest框架介绍.安装 pytest是python测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,功能更强大 pytest特征 1:断言提示信 ...

  2. Redis安装介绍

    Redis安装介绍 一.Linux版本及配置 1.  Linux版本:Red Hat Enterprise Linux 6虚拟机 2.  配置: 内存:1G:CPU:1核:硬盘:20G 二.Redis ...

  3. Docker版本与安装介绍

    Docker版本与安装介绍 Docker-CE 和 Docker-EE Centos 上安装 Docker-CE Ubuntu 上安装 Docker-CE Docker-CE和Docker-EE Do ...

  4. 三、安装cmake,安装resin ,tars服务,mysql 安装介绍,安装jdk,安装maven,c++ 开发环境安装

    三.安装cmake,安装resin 2018年07月01日 21:32:05 youz1976 阅读数:308   开发环境说明: centos7.2 ,最低配置:1核cpu,2G内存,1M带宽 1. ...

  5. iOS自动化探索(四)自动化测试框架pytest - 安装和使用

    自动化测试框架 - pytest pytest是Python最流行的单元测试框架之一, 帮助更便捷的编写测试脚本, 并支持多种功能复杂的测试场景, 能用来做app测试也能用作函数测试 官方文档: ht ...

  6. Docker版本与centos和ubuntu环境下docker安装介绍

    # Docker版本与安装介绍 * Docker-CE 和 Docker-EE * Centos 上安装 Docker-CE * Ubuntu 上安装 Docker-CE ## Docker-CE和D ...

  7. Pytest测试框架(一):pytest安装及用例执行

    PyTest是基于Python的开源测试框架,语法简单易用,有大量的插件,功能非常多.自动检测测试用例,支持参数化,跳过特定用例,失败重试等功能. 安装 pip install -U pytest  ...

  8. 一、pytest的介绍和安装

    需要针对一个项目系统开发一套UI自动化测试脚本,自己结合着学习,采用了pytest去实现,这里留下记录. 什么是pytest pytest 是一个非常成熟的全功能的Python测试框架 可以胜任uni ...

  9. pytest一:pytest 框架介绍

    pytest 是 python 的一种单元测试框架,与python 自带的 unittest测试框架类似,但是比 unittest 框架使用起来更简洁,效率更高.根据pytest 的官方网站介绍,它具 ...

随机推荐

  1. Tensorflow 教程系列 | 莫烦Python

    Tensorflow 简介 1.1 科普: 人工神经网络 VS 生物神经网络 1.2 什么是神经网络 (Neural Network) 1.3 神经网络 梯度下降 1.4 科普: 神经网络的黑盒不黑 ...

  2. sql语句exists 用法

    参考:SQL语句exists用法,Sql语句中IN和exists的区别及应用 现在有三张表 学生表S: sno ,sname 课程表C:cno ,cname 学生选课表SC: sno ,cno 查询选 ...

  3. 安装golang web框架 gin

    gin 地址https://github.com/gin-gonic/gin#installation 去gin 地址 clone 下来,放到对应的包中即可.如:gin就放在项目文件夹/github. ...

  4. Linux安装python3.6 和pip

    Linux下安装Python3.6和第三方库   如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境, 比如yum!!! ...

  5. Vue中使用JSX语法

    一 项目结构 二 App组件 <template> <div id="app"> <fruit/> </div> </temp ...

  6. LeetCode算法题-Backspace String Compare(Java实现)

    这是悦乐书的第327次更新,第350篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第197题(顺位题号是844).给定两个字符串S和T,如果两个字符串都输入到空文本编辑器 ...

  7. 区间gcd

    http://codeforces.com/problemset/problem/914/D 题意:给你n个数,两种操作:1.询问区间[l,r]在至多一次修改一个数的条件下区间gcd是否等于x. 2. ...

  8. 洛谷 P1484 种树(优先队列,贪心,链表)

    传送门 解题思路 第一眼的贪心策略:每次都选最大的. 但是——不正确! 因为选了第i个树,第i-1和i-1棵树就不能选了.所以,要有一个反悔操作. 选了第i个后,我们就把a[i]的值更新为a[l[i] ...

  9. oracle管理基础知识

    1.oracle的安装 win下 linux下 2.内存和后台进程=实例 为何将oracle做的如此复杂呢 1.内存: --提高查询速度 --提升处理数据的速度 2.后台进程 --为了完成特定的服务, ...

  10. 1、Java语言概述与开发环境——JDK JRE JVM理解

    一.理解概念: 1.JDK(Java Development Kit Java开发工具包) JDK是提供给Java开发人员使用的,其中包含Java的开发工具,也包括JRE,所以安装了JDK,就不用单独 ...