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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。