pytest運行指定用例
隨着軟件功能的增加,模塊越來越多,也意味用例越來越多,為了節約執行時間,快速得到測試報告與結果,在工作中可以通過運行指定用例,達到快速執行用例
- 例子目錄
- spec_sub1_modul_test.py
#coding: UTF-8 import pytest def test_004_spec(): assert 1==1 def test_005_spec(): assert True==False class Test_Class(): def test_006_spec(self): assert 'G' in "Goods"
- spec_sub2_modul_test.py
#coding: UTF-8 import pytest def test_007_spec(): assert 1==1 def test_008_spec(): assert True==False class Test_Class(): def test_009_spec(self): assert 'G' in "Goods"
-
spec_001_modul_test
#coding: UTF-8 import pytest def test_001_spec(): assert 1==1 def test_002_spec(): assert True==False class Test_Class(): def test_003_spec(self): assert 'H' in "Hell,Jerry"
-
運行指定模塊
if __name__ == '__main__': pytest.main("-v -s spec_001_modul_test.py")
-
運行批量文件夾(運行當前文件夾包括子文件夾所有用例)
#coding: UTF-8 import pytest if __name__ == '__main__': pytest.main("-v -s ./")
- 運行指定文件夾(subpath1目錄下面所有用例)
#coding: UTF-8 import pytest if __name__ == '__main__': pytest.main("-v -s subpath1/")
-
運行模塊中指定用例 (運行模塊中test_001_spec用例)
if __name__ == '__main__': pytest.main("-v -s spec_001_modul_test.py::test_001_spec")
-
運行class中指定的用例(運行模塊中Test_Class類test_003_spec方法)
if __name__ == '__main__': pytest.main("-v -s spec_001_modul_test.py::Test_Class::test_003_spec")
-
模糊匹配運行用例(匹配當前目錄下面包含)
if __name__ == '__main__': #運行spec_001_modul_test模塊中用例名稱包含spec的用例 pytest.main("-v -s -k spec spec_001_modul_test.py") #運行當前文件夾匹配Test_Class的用例,類文件下面的用例 pytest.main('-s -v -k Test_Class')
歡迎一起交流(群號:575479860)