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