zoukankan      html  css  js  c++  java
  • pytest标记:查找策略、标记测试函数

    pytest标记

    • pytest查找策略
    • 标记测试函数

    pytest查找策略,默认情况下,pytest会递归查找当前目录下所以以test开始或结尾的python脚本,并执行文件内所有以test开始或结束的函数和方法

    实例:

    import pytest
    
    class TestCase02(object):
        def test01(self):
            print('test01')
    
        def add(self):
            print('add')
    
        def test02(self):
            print('test02')
    
    if __name__ == '__main__':
        pytest.main(['-vs','test02.py'])

    执行结果如下:

    仅执行test01和test02,未执行add

    标记测试函数

    由于某种原因(如test_func2的功能尚未开发完成),我们只想执行指定的测试函数,在pytest中有几种解决方法:

    1、显示指定函数名,通过::标记

    test_no_mark.py::test_func1

    2、使用模糊匹配,使用-k选项标识

    pytest -k func1 test_no_mark.py

    3、使用pytest.mark在函数上进行标记

    给用例打标签

    注册标签名,通过.ini配置文件,格式如下:

    [pytest]

    markers =

    do:do

    undo:undo

    在用例上打标记

    
    
    import pytest
    
    @pytest.mark.do
    def test1():
        print('1')
    # ::  -k test  mark
    @pytest.mark.undo
    def test2():
        print('2')

    配置文件:

  • 相关阅读:
    office 2007 验证失败的解决方法
    google开不了(解决办法)
    Mobilenet V1
    Windows10系统下IDECLion的安装与配置
    单目相机成像过程
    C++中如何在函数中返回局部变量的指针/引用/地址?
    ResNeXt论文阅读笔记.md
    Mobilenet V2
    Xception
    InceptionV4
  • 原文地址:https://www.cnblogs.com/yronl/p/14463522.html
Copyright © 2011-2022 走看看