pytest---用例執行順序


一、不同文件的執行順序

 按照目錄文件名順序執行,目錄結構如下:

用例執行順序:

二、同一文件下的執行順序

按照用例順序從上到下執行,示例代碼:

import pytest class TestF(): def testz(self): print('testz') def test3(self): print('test3') def test2(): print('test2') def test1(): print('test1') def testb(): print('testb') def testa(): print('testa') if __name__ == '__main__': pytest.main()

執行結果:

三、改變用例執行順序

pip install pytest-ordering

示例代碼:

import pytest class TestF(): def testz(self): print('testz') def test3(self): print('test3') def test2(): print('test2') def test1(): print('test1') @pytest.mark.run(order=2) def testb(): print('testb') @pytest.mark.run(order=1) def testa(): print('testa') if __name__ == '__main__': pytest.main()

執行結果(對比二中的執行結果)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM