pytest-运行用例
新建 test_pytest_marker.py 文件
import pytest @pytest.mark.webtest def test_send_http(): pass @pytest.mark.test0 def test_something_quick(): pass def test_another(): pass class TestClass: def test_method(self): pass
在cmd 进入文件目录,或者在pycharm的Terminal中 运行
1 pytest的mark机制
只运行带‘webtest’的用例
pytest -v -m 'webtest' test_pytest_marker.py
运行不带‘webtest’的用例
pytest -v -m ‘not webtest' test_pytest_marker.py
2. 选择运行特定的某个测试用例
你可以按照某个测试用例的的模块,类或函数来选择你要运行的case,比如下面的方式就适合一开始在调试单个测试用例的时候。
pytest -v test_pytest_markers.py::TestClass::test_method
3. 选择运行特定的某个类
pytest -v test_pytest_markers.py::TestClass
4 多种组合
pytest -v test_pytest_markers.py::TestClass test_pytest_markers.py::test_send_http
5 用-k进行关键字匹配来运行测试用例名字子串
pytest -v -k http test_pytest_markers.py
浙公网安备 33010602011771号