pytest指定节点的测试用例

pytest 为每一个收集到的测试用例指定一个唯一的nodeid,它由模块名说明符构成,以::间隔,其中说明符可以包含类名、函数名和由parametrize标记赋予的参数。

示例testNode.py,如下:

import pytest

def test_one():

    pass

class TestNode:

    def test_one(self):

        pass

    @pytest.mark.parameterize("x, y", [(1,3), (3, 5)])

    def test_two(self,  x, y):

        assert x+2 == y


1) pytest testNode.py::test_one                            - 函数名

2) pytest testNode.py::testNode::test_one            - 类名+函数名

3) pytest testNode.py::testNode::test_two[1-3]     - 类名+函数名+标记参数

4) pytest testNode.py::testNode::test_two[3-5]     - 类名+函数名+标记参数

注意:指定参数x、y的形式是[1-1],中间以-间隔,并且只能为[1-3]或者[3-5],不能是[1, 3]、[3, 5]、(1, 3)、(3, 5).

另可以使用-vv来查看test cases的执行细节

5) pytest testNode.py -vv                                       - 类名+函数名+标记参数

-vv

你可能感兴趣的:(pytest指定节点的测试用例)