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. lua 十进制转二进制

    -- Converts a byte to a string of 0s and 1s. function byte2bin(n) local t = {} for i=7,0,-1 do t[#t+ ...

  2. BigDecimal进行加减乘除计算

    以前大部分关于查询计算的逻辑是在sql语句中执行的,但是有时候会出现比较复杂的计算情况,需要我们在代码中进行计算,这个时候使用BigDecimal进行计算会很方便. BigDecimal num1 = ...

  3. LeetCode算法题-Shortest Distance to a Character(Java实现)

    这是悦乐书的第321次更新,第343篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第191题(顺位题号是821).给定字符串S和字符C,返回一个整数数组,表示字符串中所有 ...

  4. Vim常用的功能命令

    一.编辑 查看行号     :set nu 删除一整行   dd 删除1到10行     :1,10d 删除所有内容     dG 当前行下插入一空行   o 撤销改动    u 查看当前行信息    ...

  5. Java第二周总结

    一.Java 基础程序设计 第一章: (1)在Java中源文件的扩展名为.java,编译Java源程序文件产生相应的字节码文件扩展名为.class (2)public class定义要求类名称保持一致 ...

  6. 【Linux 环境搭建】ubuntu 的samba配置

    在/etc/samba/smb.conf的文件末尾增加下面的内容然后重启samba [home] comment = James Harden path = / browseable = yes wr ...

  7. JS观察者设计模式:实现iframe之间快捷通信

    观察者设计模式又称订阅发布模式,在JS中我们习惯叫做广播模式,当多个对象监听一个通道时,只要发布者向该通道发布命令,订阅者都可以收到该命令,然后执行响应的逻辑.今天我们要实现的就是通过观察者设计模式, ...

  8. HDU 1231 题解

    题面: 最大连续子序列 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...

  9. Python作图包含type3字体解决方案

    1. 解决方案 matplotlib.rcParams[‘text.usetex’] = True

  10. BZOJ 5317: [Jsoi2018]部落战争

    传送门 写出式子,若存在 $a \in A$,$b \in B$,使得 $b+v=a$,那么此方案会产生冲突 即存在 $a \in A$,$b \in B$,使得 $v=a+(-b)$,设 $C=A+ ...