Pytest学习(八) - 自定义标记mark的使用html
pytest 支持自定义标记,自定义标记方便用例模块划分,也能够理解方便管理,配合标记参数 -m使用微信
# -*- coding: utf-8 -*- # @Time : 2020/11/15 9:51 # @Author : longrong.lang # @FileName: test_mark.py # @Software: PyCharm # @Cnblogs :https://www.cnblogs.com/longronglang import pytest @pytest.mark.mylogin def test_login(): print('登陆成功!') @pytest.mark.query def test_query(): print('检索商品成功!') @pytest.mark.addcart def test_addcart(): print('加入购物车') if __name__ == '__main__': # pytest -s -m query test_mark.py pytest.main(['-s', '-m query', 'test_mark.py'])
pytest -s -m query test_mark.py
可能看到这的同窗会问了,为何不用main方法执行,我代码里虽然写了,可是main执行就变成了了所有执行,这点我也很迷糊,为何不行呢。有解决的同窗,请在文末留言,我也学习下。
运行结果以下:ide
建立一个pytest.ini文件,文件须要和运行的测试用例同一个目录,或在根目录下做用于全局。
加上自定义mark,内容以下:学习
[pytest] markers = mylogin: this is mylogin page query: this is query page addcart: this is addcart page
执行命令以下:测试
pytest -s -m "not query" test_mark.py
运行结果以下:this
执行命令以下:命令行
pytest -s -m "query or mylogin" test_mark.py
运行结果以下:
系列参考文章:
https://www.cnblogs.com/poloyy/category/1690628.htmlcode
EOFhtm
本文做者:久曲建的测试窝
本文连接:https://www.cnblogs.com/longronglang/p/13976509.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客全部文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:若是您以为文章对您有帮助,能够点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!blog
欢迎关注个人微信公众号:软件测试君