Pytest自定义标记mark及特定运行方式

 
mark 标记
 

标记执行指定类

pytest.main(['-s','文件名','-m=标记名'])

pytest.main(['-s','test01.py','-m=test'])

import pytest
@pytest.mark.test
class Test(object):
    def test_01(self):
        print('test_01')
    def test_02(self):
        print('test_02')
if __name__=='__main__':
    #运行指定的类
    pytest.main(['-s','test01.py','-m=test'])


"C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/Test/test/test01.py
============================= test session starts =============================
platform win32 -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0
rootdir: C:\Users\wangli\PycharmProjects\Test\test
plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0
collected 2 items

test01.py test_01
.test_02
.

============================== warnings summary ===============================
C:\Program Files\Python35\lib\site-packages\_pytest\mark\structures.py:324
  C:\Program Files\Python35\lib\site-packages\_pytest\mark\structures.py:324: PytestUnknownMarkWarning: Unknown pytest.mark.test - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    PytestUnknownMarkWarning,

-- Docs: https://docs.pytest.org/en/latest/warnings.html
======================== 2 passed, 1 warnings in 0.05s ========================

Process finished with exit code 0

标记执行非指定方法 

pytest.main(['-s','文件名','-m=not 标记名'])

pytest.main(['-s','test01.py','-m=not test'])

import pytest

class Test(object):
    @pytest.mark.test
    def test_01(self):
        print('test_01')
    def test_02(self):
        print('test_02')
if __name__=='__main__':
    #运行指定的类
    pytest.main(['-s','test01.py','-m=not test'])


"C:\Program Files\Python35\python.exe" C:/Users/wangli/PycharmProjects/Test/test/test01.py
============================= test session starts =============================
platform win32 -- Python 3.5.2, pytest-5.1.2, py-1.8.0, pluggy-0.12.0
rootdir: C:\Users\wangli\PycharmProjects\Test\test
plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0
collected 2 items / 1 deselected / 1 selected

test01.py test_02
.

============================== warnings summary ===============================
C:\Program Files\Python35\lib\
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王大力测试进阶之路

打赏博主喝瓶水吧!!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值