Pytest运行测试用例

import pytest

@pytest.mark.P0

def test_case1():

pass # perform some P0 test for your app

def test_case2():

pass

def test_case3():

pass

class TestClass:

def test_case4(self):

pass


1.选择运行特定的某个类
你可以按照某个测试用例的的模块,类或函数来选择你要运行的case
>pytest -v test_pytest_markers.py::TestClass

2.选择运行特定的某个测试用例, 适合一开始在调试单个测试用例的时候。
pytest -v test_pytest_markers.py::TestClass::test_method

3.多种组合运行
>pytest -v test_pytest_markers.py::TestClass test_pytest_markers.py::test_send_http

4.用-k进行关键字匹配来运行测试用例名字子串
>pytest -v -k case1 test_pytest_markers.py

Pytest Marker 机制

5.用Marker运行
对于Pytest的测试用例,可以在每一个测试用例加一个marker,比如pytest运行的时就只运行带有该marker的测试用例,比如下面的@pytest.mark.P0。
pytest -v -m "P0" test_pytest_markers.py

猜你喜欢

转载自865325772.iteye.com/blog/2403763