pytest运行指定用例

发表于:2019-6-26 16:53

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:天谈    来源:博客园

  随着软件功能的增加,模块越来越多,也意味用例越来越多,为了节约执行时间,快速得到测试报告与结果,在工作中可以通过运行指定用例,达到快速执行用例
  例子目录
  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),我们将立即处理。
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号