pytest.ini 中mark 与pytest中标记模块使用方法

文章描述了如何在pytest中使用标记(@pytest.mark)来组织和运行测试用例,以及通过命令行参数指定特定标记进行筛选。测试用例包括基本的断言和打印操作,展示了不同标记的效果。
摘要由CSDN通过智能技术生成
import pytest
@pytest.mark.mark3
class Test_mark():
    @pytest.mark.mark2
    def test_03(self):
        a = 1
        b = 2
        c = 3
        assert a==b
    @pytest.mark.mark1
    def test_04(self):
        a = 1
        b = 2
        c = 3
        print(1)
        assert a<c
    def test_01(self):
        a = 1
        b = 2
        c = 3
        print(1)
        assert a > c
def test_02():
    a = 1
    b = 2
    c = 3
    print(1)
    assert a == c
if __name__ == '__main__':
    pytest.main(['-m mark3 and not mark1','test.py'])

F:\测试\python\Python36\python.exe F:/测试/pycharm-project/myproject/test.py
============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-7.0.1, pluggy-1.0.0
rootdir: F:\测试\pycharm-project\myproject, configfile: pytest.ini
plugins: ordering-0.6
collected 4 items / 2 deselected / 2 selected

test.py FF                                                               [100%]

================================== FAILURES ===================================
______________________________ Test_mark.test_03 ______________________________

self = <test.Test_mark object at 0x000002BD2BC4D5C0>
[pytest]
#addopts =-m --alluredir ./temp
testpaths = ./myproject
python_files = test*.py
python_classes = Test*
python_functions = test*
markers=
    mark1
    mark2
    mark3

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值