随着软件功能的增加,模块越来越多,也意味用例越来越多,为了节约执行时间,快速得到测试报告与结果,在工作中可以通过运行指定用例,达到快速执行用例
例子目录
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') |
上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。