pytest如何执行用例及常见code含义(二)

有两种运行方式,这里要再强调一下,测试的方法必须是test_开头,文件名字是test_*.py or *_test.py
第一种方式,Windows系统通过DOS框,输入命令进入到文件所在的目录,输入命令pytest,可执行该文件下的所有用例文件
在这里插入图片描述
若不想执行所有文件,想指定文件执行,可通过命令:pytest -q [用例名]如图所示:
在这里插入图片描述
第二种执行方式,也可通过pycharm执行用例
1、右键执行代码,
在这里插入图片描述
测试结果如下:
在这里插入图片描述
运行的一些命令:

pytest test_mod.py 运行一个具体的模块
pytest testing/ 运行一个路径下的所有case
pytest -k “MyClass and not method” 运行包含MYClass类中的case,但是不包含名字为“method”这个case
pytest test_mod.py::test_func 运行模块中的方法
pytest test_mod.py::TestClass::test_method 运行模块中的类中的方法
pytest -m slow 将会运行所有被装饰器装饰过的方法,比如 @pytest.mark.slow
pytest --pyargs pkg.testing 运行testing包中的case
pytest -x # stop after first failure 在第一个case失败以后就停止
pytest --maxfail=2 # stop after two failures 在第二个case失败以后就停止

执行完命令的一些code的含义:
| Exit code 0: | All tests were collected and passed successfully,所有的用例都被收集完成而且执行成功 |
|-Exit code 1:-|Tests were collected and run but some of the tests failed 所有的用例都被收集完成,但是失败了一些|
| Exit code 2: | Test execution was interrupted by the user 执行过程中被执行者终止 |
| Exit code 3: | Internal error happened while executing tests 执行过程中内部发生错误 |
|Exit code 4:|pytest command line usage error pytest命令有错误|
|Exit code 5: |No tests were collected 没有用例被收集 |

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值