import pytest
"""
 使用pytest编写用例,必须遵守以下规则:
    (1)测试文件名必须以“test_”开头或者"_test"结尾(如:test_ab.py)
  (2)测试方法必须以“test_”开头。
  (3)测试类命名以"Test"开头。
"""

"""
@pytest.fixture(scope='')
    function:每个test都运行,默认是function的scope
    class:每个class的所有test只运行一次
    module:每个module的所有test只运行一次
    session:每个session只运行一次
"""

@pytest.fixture(scope='function')
def setup_function(request):
    def teardown_function():
        print("teardown_function called.")
    request.addfinalizer(teardown_function)  # 此内嵌函数做teardown工作
    print('setup_function called.')

@pytest.mark.website
def test_1(setup_function):
    print('Test_1 called.')

@pytest.fixture(scope='module')
def setup_module(request):
    def teardown_module():
        print("teardown_module called.")
    request.addfinalizer(teardown_module)
    print('setup_module called.')

def test_2(setup_module):
    print('Test_2 called.')

def test_3(setup_module):
    print('Test_3 called.')
    assert 2==1+1

if __name__ == '__main__':
    """
    Console参数介绍
        -v 用于显示每个测试函数的执行结果
        -q 只显示整体测试结果
        -s 用于显示测试函数中print()函数输出
        -x, --exitfirst, exit instantly on first error or failed test
        -h 帮助
    """
    """
    报告参数 _report.html   ./_report.html   ./report/_report.html    ../report/_report.html    #./当前文件夹,../上个文件夹
        --resultlog=./log.txt
        --junitxml=./log.xml
        --pastebin=all
        --html=./report.html
    """

    #两者方法相同,执行该目录下所有的test文件
    #pytest.main()
    #pytest.main(["D:\codeBook\pyhton\shuzf_demo\other\pytest"])

    # pytest.main(['run_pytest.py'])
    # pytest.main(['-q', 'run_pytest.py'])         #多了版本信息
    # pytest.main(['-s', 'run_pytest.py'])         #以print信息显示
    # pytest.main(['-s', 'run_pytest.py', '--html=_report.html'])

pytest-生成测试报告的更多相关文章

  1. Python单元测试框架之pytest -- 生成测试报告

    继续pytest单元测试框架的学习,pytest可以生成多种类型的测试报告.这一节就来学习pytest如何生成测试报告. 创建test_calss.py 测试用例文件,这里以测试该文件为例. #cod ...

  2. Allure+pytest 生成测试报告

    简介: python 主流自动化测试报告插件有三个:HTMLTestRunner.BeautifulReport 和 Allure.HTMLTestRunner是一个比较古老的报告模板,界面也不是很好 ...

  3. pytest生成测试报告

    生成JunitXML格式的测试报告    --junitxml=report\h.xml 生成result log 格式的测试报告     --resultlog=report\h.log 生成htm ...

  4. pytest生成测试报告-4种方法

    1.生成resultlog文件 2.生成JunitXML文件 3.生成html测试报告 > pip install pytest-html     # 通过pip安装pytest-html 4. ...

  5. Python单元测试框架之pytest 2 -- 生成测试报告

    From: https://www.cnblogs.com/fnng/p/4768239.html Python单元测试框架之pytest -- 生成测试报告 2015-08-29 00:40 by ...

  6. Pytest+allure生成测试报告

    1.Allure.zip包的下载地址: https://github.com/allure-framework/allure2 在跳转页面选择一个allure.zip包的版本下载 若以上方法无法下载z ...

  7. Pytest测试框架(五):pytest + allure生成测试报告

    Allure 是一款轻量级.支持多语言的开源自动化测试报告生成框架,由Java语言开发,可以集成到 Jenkins. pytest 测试框架支持Allure 报告生成. pytest也可以生成juni ...

  8. pytest+jenkins+allure 生成测试报告发送邮件

    前言第一部分:Pycharm for Gitee1. pycharm安装gitee插件2. gitee关联本地Git快速设置- 如果你知道该怎么操作,直接使用下面的地址简易的命令行入门教程:3. Gi ...

  9. 使用allure工具生成测试报告(基于pytest框架)

    一.allure简介:一个轻量级的,灵活的,支持多语言,多平台的开源report框架 Allure基于标准的xUnit结果输出,但是添加了一些补充数据.任何报告都是通过两个步骤生成的.在测试执行期间( ...

  10. python + pytest + allure生成测试报告

    pytest结合allure生成测试报告 环境搭建 要安装java环境,版本要是jdk1.8的,配置好java环境变量,不然输入allure命令会报错,JAVA_HOME环境,自行配置 安装allur ...

随机推荐

  1. 系统分析与设计HW5

    个人作业 领域建模 a. 阅读 Asg_RH 文档,按用例构建领域模型. 按 Task2 要求,请使用工具 UMLet,截图格式务必是 png 并控制尺寸 说明:请不要受 PCMEF 层次结构影响.你 ...

  2. 思维导图之kubernetes

    k8s docker

  3. 【MM系列】SAP 物料帐下修改物料的价格

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 物料帐下修改物料的价格   ...

  4. FTP搭建YUM源服务器

    一.FTP搭建YUM源服务器 1.服务器 挂载centos镜像[root@localhost ~]#yum install vsftpd[root@localhost ~]#systemctl sta ...

  5. 机器学习实战-Logistics回归

    Logistics回归:实战,有两个特征X0,X1.100个样本,进行Logistics回归 1.导入数据 def load_data_set(): """ 加载数据集 ...

  6. 解决172.17 或者172.18 机房环境下harbor服务器不通的问题

    直接改docker-compose.yml文件: 把原来的network选项注释掉,自定义 #networks: # harbor: # external: false networks: harbo ...

  7. django 的 MTV 流程图

  8. java http请求工具整理

    处理了http 的get和post的请求,分别支持同步处理,异步处理两种方式下见代码. @Slf4jpublic class HttpUtils { /** * 同步请求http请求 不推荐 * * ...

  9. php读取excel文件并导入数据库(表头任意设定)

    最近收到一个很奇葩的需求,要求上传excel员工工资表,表格表头不固定,导入后字段名为表头的拼音,每月导入一次,当月重复导入则覆盖现有的当月表头,并且可以按照在界面上按照月份筛选显示,我写的代码主要包 ...

  10. django后台集成富文本编辑器Tinymce的使用

    富文本编辑器Tinymce是使用步骤: 1.首先去python的模块包的网站下载一个django-tinymce的包 2.下载上图的安装包,然后解压,进入文件夹,执行: (pychrm直接运行命令pi ...