日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/3/15 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Pytest自定义标记mark及特定运行方式 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
mark 標(biāo)記

標(biāo)記執(zhí)行指定類

pytest.main(['-s','文件名','-m=標(biāo)記名'])

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__':#運(yùn)行指定的類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 itemstest01.py test_01 .test_02 .============================== warnings summary =============================== C:\Program Files\Python35\lib\site-packages\_pytest\mark\structures.py:324C:\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.htmlPytestUnknownMarkWarning,-- Docs: https://docs.pytest.org/en/latest/warnings.html ======================== 2 passed, 1 warnings in 0.05s ========================Process finished with exit code 0

標(biāo)記執(zhí)行非指定方法?

pytest.main(['-s','文件名','-m=not 標(biāo)記名'])

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

import pytestclass Test(object):@pytest.mark.testdef test_01(self):print('test_01')def test_02(self):print('test_02') if __name__=='__main__':#運(yùn)行指定的類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 selectedtest01.py test_02 .============================== warnings summary =============================== C:\Program Files\Python35\lib\site-packages\_pytest\mark\structures.py:324C:\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.htmlPytestUnknownMarkWarning,-- Docs: https://docs.pytest.org/en/latest/warnings.html ================= 1 passed, 1 deselected, 1 warnings in 0.05s =================Process finished with exit code 0 -v 指定的函數(shù)節(jié)點(diǎn) id 指定執(zhí)行.py文件 pytest.main(['-v','文件名.py'])??pytest.main(['-v','test01.py']) import pytest class Test(object):def test_01(self):print('test_01')def test_02(self):print('test_02') if __name__=='__main__':pytest.main(['-v','test01.py'])"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 -- C:\Program Files\Python35\python.exe cachedir: .pytest_cache metadata: {'Platform': 'Windows-10-10.0.18362-SP0', 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.8.0_101', 'Plugins': {'html': '1.22.0', 'metadata': '1.8.0', 'allure-pytest': '2.8.5'}, 'Python': '3.5.2', 'Packages': {'pluggy': '0.12.0', 'py': '1.8.0', 'pytest': '5.1.2'}} rootdir: C:\Users\wangli\PycharmProjects\Test\test plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collecting ... collected 2 itemstest01.py::Test::test_01 PASSED [ 50%] test01.py::Test::test_02 PASSED [100%]============================== 2 passed in 0.09s ==============================Process finished with exit code 0

指定執(zhí)行文件下_類

pytest.main(['-v','文件名.py::類名'])? ??pytest.main(['-v','test01.py::Test'])

cmd下pytest -v test_server.py::TestClass

import pytest class Test(object):def test_01(self):print('test_01')def test_02(self):print('test_02') if __name__=='__main__':pytest.main(['-v','test01.py::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 -- C:\Program Files\Python35\python.exe cachedir: .pytest_cache metadata: {'Plugins': {'html': '1.22.0', 'allure-pytest': '2.8.5', 'metadata': '1.8.0'}, 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.8.0_101', 'Python': '3.5.2', 'Packages': {'pytest': '5.1.2', 'py': '1.8.0', 'pluggy': '0.12.0'}, 'Platform': 'Windows-10-10.0.18362-SP0'} rootdir: C:\Users\wangli\PycharmProjects\Test\test plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collecting ... collected 2 itemstest01.py::Test::test_01 PASSED [ 50%] test01.py::Test::test_02 PASSED [100%]============================== 2 passed in 0.05s ==============================Process finished with exit code 0

指定執(zhí)行文件下_類_方法

pytest.main(['-v','文件名.py::類名::方法名'])??pytest.main(['-v','test01.py::Test::test_02'])

cmd下pytest -v test_server.py::TestClass::test_method

import pytest class Test(object):def test_01(self):print('test_01')def test_02(self):print('test_02') if __name__=='__main__':pytest.main(['-v','test01.py::Test::test_02'])"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 -- C:\Program Files\Python35\python.exe cachedir: .pytest_cache metadata: {'Packages': {'pytest': '5.1.2', 'pluggy': '0.12.0', 'py': '1.8.0'}, 'Plugins': {'allure-pytest': '2.8.5', 'html': '1.22.0', 'metadata': '1.8.0'}, 'Platform': 'Windows-10-10.0.18362-SP0', 'Python': '3.5.2', 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.8.0_101'} rootdir: C:\Users\wangli\PycharmProjects\Test\test plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collecting ... collected 1 itemtest01.py::Test::test_02 PASSED [100%]============================== 1 passed in 0.05s ==============================Process finished with exit code 0

指定執(zhí)行多個(gè)節(jié)點(diǎn),文件下_類、文件_類_方法

pytest.main(['-v','文件名.py::類名::方法名','文件名.py::類名'])? ?pytest.main(['-v','test01.py::Test::test_02','test01.py::Test'])

cmd下用pytest -v test_server.py::TestClass test_server.py::test_send_http

import pytest class Test(object):def test_01(self):print('test_01')def test_02(self):print('test_02') if __name__=='__main__':pytest.main(['-v','test01.py::Test::test_02','test01.py::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 -- C:\Program Files\Python35\python.exe cachedir: .pytest_cache metadata: {'Python': '3.5.2', 'Platform': 'Windows-10-10.0.18362-SP0', 'Packages': {'py': '1.8.0', 'pluggy': '0.12.0', 'pytest': '5.1.2'}, 'Plugins': {'metadata': '1.8.0', 'html': '1.22.0', 'allure-pytest': '2.8.5'}, 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.8.0_101'} rootdir: C:\Users\wangli\PycharmProjects\Test\test plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collecting ... collected 3 itemstest01.py::Test::test_02 PASSED [ 33%] test01.py::Test::test_01 PASSED [ 66%] test01.py::Test::test_02 PASSED [ 66%]============================== 3 passed in 0.08s ==============================Process finished with exit code 0

-s模式執(zhí)行

-s執(zhí)行多個(gè).py文件

pytest.main(['-s','文件1.py','文件2.py'])

test01.pyimport pytest class Test(object):def test_01(self):print('test_01')def test_02(self):print('test_02')assert 1==1 if __name__=='__main__':pytest.main(['-s','test01.py','test02.py'])"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 10 itemstest01.py test_01 .test_02 . test02.py 22222222 {'sex': '男', 'score': '及格', 'classes': '一班'} .{'sex': '女', 'score': '及格', 'classes': '一班'} .{'sex': '男', 'score': '及格', 'classes': '二班'} .{'sex': '女', 'score': '及格', 'classes': '二班'} .{'sex': '男', 'score': '不及格', 'classes': '一班'} .{'sex': '女', 'score': '不及格', 'classes': '一班'} .{'sex': '男', 'score': '不及格', 'classes': '二班'} .{'sex': '女', 'score': '不及格', 'classes': '二班'} .============================= 10 passed in 0.10s ==============================Process finished with exit code 0

-s執(zhí)行.py文件下的類

pytest.main(['-s','文件.py::類名'])

import pytest class Test(object):def test_01(self):print('test_01')def test_02(self):print('test_02')assert 1==1 if __name__=='__main__':pytest.main(['-s','test01.py::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 itemstest01.py test_01 .test_02 .============================== 2 passed in 0.04s ==============================Process finished with exit code 0

-K指定匹配用例名稱執(zhí)行

pytest.main(['-k','-v','test_01'])

pytest.main(['-k','not test_01','-v'])

pytest.main(['-k','用例名1 or 用例名2','-v'])

import pytest class Test(object):def test_01(self):print('test_01')def test_02(self):print('test_02')assert 1==1 if __name__=='__main__':pytest.main(['-k','test_01 or test_02','-v'])"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 -- C:\Program Files\Python35\python.exe cachedir: .pytest_cache metadata: {'Python': '3.5.2', 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.8.0_101', 'Packages': {'pytest': '5.1.2', 'py': '1.8.0', 'pluggy': '0.12.0'}, 'Platform': 'Windows-10-10.0.18362-SP0', 'Plugins': {'allure-pytest': '2.8.5', 'html': '1.22.0', 'metadata': '1.8.0'}} rootdir: C:\Users\wangli\PycharmProjects\Test\test plugins: allure-pytest-2.8.5, html-1.22.0, metadata-1.8.0 collecting ... collected 0 items============================ no tests ran in 0.65s ============================Process finished with exit code 0

?

cmd下運(yùn)行:

pytest -v -k 用例名

pytest -k ‘not 用例名’? -v

pytest -k ‘用例名1 or 用例名2’? -v

?

總結(jié)

以上是生活随笔為你收集整理的Pytest自定义标记mark及特定运行方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。