pytest
qq_39149099
这个作者很懒,什么都没留下…
展开
-
2021-11-10
关键字:--rerunspytest运行参数--reruns主要用于用例运行失败后,重新运行失败的用例,运行规则为遇到失败的用例,就根据重试次数运行失败的用例,然后在执行剩下的用例。举例如下:import pytestclass TestPytestFeatures(object): def test_case_login(self): num = 1 assert num == 2 def test_case_logout(self):原创 2021-11-10 09:21:18 · 513 阅读 · 0 评论 -
pytest特性记录:并发运行测试用例
关键字:-npytest运行参数 -n用于并发运行多个测试用例,该并发运行是进程级别的并发测试,使用前,需安装pytest-xdist插件。其中 -n=auto表示使用服务器所有的CPU来运行测试用例,举例如下:import timeimport pytestclass TestPytestFeatures(object): def test_case_login(self): time.sleep(1) num = 1 assert原创 2021-11-10 09:04:31 · 1239 阅读 · 0 评论 -
pytest特性记录:运行指定测试用例
关键字:-kpytest运行参数 -k用于运行指定的测试用例,比如在某一个py文件中,进行脚本调试,此时只想运行某一个用例,则可以使用该参数。举例如下:import pytestclass TestPytestFeatures(object): def test_case_login(self): num = 1 assert num == 1 def test_case_logout(self): tmp = ["a", "原创 2021-11-10 08:42:05 · 2365 阅读 · 0 评论 -
pytest特性记录:打印失败用例的局部变量
关键字:-lpytest运行参数 -l(--showlocal),在用例执行过程中,加上-l参数,可以在用例执行失败的时候,自动打印用例内部的局部变量值,方便我们定位问题,调试代码。举例如下:import pytestclass TestPytestFeatures(object): def test_case_01(self): num = 1 assert num == 1 def test_case_02(self):原创 2021-11-09 09:21:48 · 291 阅读 · 0 评论 -
pytest特性记录:首先执行上次运行失败的用例
关键字:--ff(--failed-first)pytest运行参数 --ff(--failed-first)表示再运行测试套件的时候,先运行上次执行失败的用例,然后在执行其余的用例,即改变了用例执行顺序,优先执行失败用例。举例如下:import pytestclass TestPytestFeatures(object): def test_case_01(self): assert 1 == 1 def test_case_02(self):原创 2021-11-09 09:06:46 · 194 阅读 · 0 评论 -
pytest特性记录:仅运行上一次运行失败的测试用例
关键字:--lf(--last-failed)pytest运行参数 --lf(--last-failed),即每次运行测试套件时只运行上一次失败的测试用例,该参数是为了方便调试测试用例,提高测试效率。若第一次运行该测试套件或者上次运行时测试用例全部通过,则本次运行所有的测试用例。举例如下:# 第一次运行时用例3和4执行失败,使用了参数 --lf,则本次运行只执行运行失败的用例,即用例3、4import pytestclass TestPytestFeatures(object):原创 2021-11-09 08:58:18 · 516 阅读 · 0 评论 -
pytest特性记录:遇到用例执行失败则停止测试套件的运行
关键字:-x(--exitfirst)、--lf(--last-failed)、--ff(--failed-first)、-l(--showlocals)、-k、-n(--numprocesses)、--rerunspytest参数 -x(--exitfirst),即在测试用例调试运行过程中,遇到用例失败,则停止运行,方便我们调试脚本,对于大型项目而言,可以节省很多时间。举例如下,共4个测试用例,其中第三个测试用例运行失败,第四个用例未执行:import pytestclass TestPy原创 2021-11-09 08:46:13 · 2270 阅读 · 0 评论