zoukankan      html  css  js  c++  java
  • pytest---pytest.ini配置文件

    前言

     我们在执行用例的时候,每次都在命令行中输入-v,-s等一些命令行参数的时,比较麻烦。其中pytest.ini这个配置文件可以快速的帮助我们解决这个问题。

    配置文件

    pytest.ini文件是pytest的主配置文件,可以改变pytest的运行方式,且是一个固定的文件pytest.ini文件,pytest.ini一般存放在项目的根目录中。我们可以打开终端,在终端中输入pytest -h来查看一些pytest.ini参数配置详情,这里的参数比较多,安静只截取一部分。

    参数详解

    这里面这么多参数可能目前用不上,安静只介绍一个常用的参数信息,比如,我们每次后面跟的参数信息

    addopts

    addopts:表示可以更改默认命令行选项

    [pytest]
    # 表示可以更改默认命令行选项
    addopts = -v -s

    这样我们直接在cmd中执行pytest就会默认加上以上2个参数。将我们print的内容和用例执行结果。

    testpaths

    testpaths:表示执行用例的目录

    [pytest]
    addopts = -v -s
    testpaths = test_01

    在当前目录创建两个文件夹,其中一个是test_01,另一个是test_02目录中均存有用例。通过添加testpaths执行执行测试用例目录为test_01,这样就只会执行test_01下的目录

    python_file

    python_file:表示执行文件名

    [pytest]
    addopts = -v -s
    testpaths = test_01
    python_files = test_01.py

    在test_01的目录下存放多个test文件,通过加入python_files来固定确认执行那一个测试文件内容

    python_classes

    python_classes:表示执行的类名

    [pytest]
    addopts = -v -s
    testpaths = test_01
    python_files = test_01.py
    python_classes = Test_

    在test_01.py文件中写入两个类,不同的类名。这样就只会执行标记的类内容

    import pytest
    
    class Test_ini:
    
        def test01(self):
            print('用例01')
    
        def test02(self):
            print('用例02')
    
        def test03(self):
            print('用例03')
    
    class Testini:
        def test_01(self):
            print('用例01')
    
        def test_02(self):
            print('用例02')
    
        def test_03(self):
            print('用例03')
    
    if __name__ == '__main__':
        pytest.main(['-s'])

    通过执行,可以看到只执行了Test_的内容

    python_functions

    python_functions:表示执行方法名内容

    [pytest]
    addopts = -v -s
    testpaths = test_01
    python_files = test_01.py
    python_classes = Test
    python_functions = test_

    还是上面的数据,通过执行。

    通过上面内容,安静简单的将几个常用到的配置文件内容信息列举出来,大家也可以进行下方留言,看看还有哪些比较常用的,可以一起分享出来。

  • 相关阅读:
    88. Merge Sorted Array
    87. Scramble String
    86. Partition List
    85. Maximal Rectangle
    84. Largest Rectangle in Histogram
    83. Remove Duplicates from Sorted List
    82. Remove Duplicates from Sorted List II
    81. Search in Rotated Sorted Array II
    80. Remove Duplicates from Sorted Array II
    计算几何——点线关系(叉积)poj2318
  • 原文地址:https://www.cnblogs.com/qican/p/14592694.html
Copyright © 2011-2022 走看看