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\