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. 【MM系列】MB1A MB1B MB1C MB11 MIGO的区别解析

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]MB1A MB1B MB1C MB1 ...

  2. Redis进阶:Redis的哨兵模式搭建

    Redis进阶:Redis的哨兵模式搭建 哨兵机制介绍 单机版的Redis存在性能瓶颈,Redis通过提高主从复制实现读写分离,提高了了Redis的可用性,另一方便也能实现数据在多个Redis直接的备 ...

  3. mysql 修改成utf8编码

    参考文档 https://www.cnblogs.com/chenshuo/p/4743144.html

  4. 联想Z485安装64位ubantu

    开始今天的正式写作之前不得不吐槽一下联想电脑,真的是很垃圾!联想Z485使用的是AMD的处理器,性能差的很,更让人不能忍的是,居然不能正常安装64位ubantu.这个情况让那些想在自己笔记电脑上安装T ...

  5. [转帖]CentOS 7 使用kubeadm 部署 Kubernetes

    CentOS 7 使用kubeadm 部署 Kubernetes   关闭swap 执行swapoff临时关闭swap. 重启后会失效,若要永久关闭,可以编辑/etc/fstab文件,将其中swap分 ...

  6. ^A '\001' 分隔符

    ^A 分隔符符号\001,使用组合按键“ctrl+V+A”获得

  7. SQL server字符分割

    USE [vanke_develop] GO /****** Object: UserDefinedFunction [dbo].[func_Split] Script Date: 2019/5/22 ...

  8. 03: django进阶篇

    1.1 cookie 1.cookie简介 1. cookie实质就是客户端硬盘中存放的键值对,利用这个特性可以用来做用户验证 2. 比如:{“username”: “dachengzi”} #再次访 ...

  9. [LeetCode] 109. 有序链表转换二叉搜索树

    题目链接 : https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree/ 题目描述: 给定一个单链表,其中的 ...

  10. kotlin学习(7)高阶函数

    高阶函数 以另一个函数作为参数或者返回值的函数被称为高阶函数. 函数类型 //隐式声明(省略了变量类型) val sum = (x:Int, y:Int -> x+y) val action = ...