1个练习引发的系列学习之pytest指定测试用例 (二)
2017-11-27 10:17
621 查看
一、背景介绍
在test module下有4个测试类,15条测试用例,通过练习来熟悉使用pytest提供的指定用例集合方法。
pytest提供了多种指定测试用例集合的方式:
指定module
指定关键字
指定文件
指定标记的表达式
二、实践
以下实践均在pycharm中进行。
指定module
【Run/Debug Configuration】-【Additional Arguments】参数为空,直接运行即可。
在运行结果中,可以看到,15条测试用例均被执行了。
指定关键字
在运行时,可以通过指定-k参数,指定部分测试用例,以下是-k参数的帮助信息。
例子1:
【Run/Debug Configuration】-【Additional Arguments】-【-k "test_20"】,通过指定关键字,执行了5条与关键字匹配的测试用例
例子2:
【Run/Debug Configuration】-【Additional Arguments】-【-k "not test_20"】,通过指定关键字,忽略了test_20*的测试用例
指定文件
【Run/Debug Configuration】-【Working directory】,设置为test文件的pytest相当于执行了dayByDay目录下的test_xx.py文件。
指定标记的表达式http://i2.51cto.com/images/blog/201711/27/f4ac944da083bce97cc7c30a863fe418.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=[/img]
三、总结
通过pytest提供的指定方式,可以对测试用例进行分拣,灵活的进行选择。同时在构造测试用例的name时,要定义便于标识的keyword。
四、参考资料
[url=https://docs.pytest.org/en/latest/example/markers.html#using-k-expr-to-select-tests-based-on-their-name]https://docs.pytest.org/en/latest/example/markers.html#using-k-expr-to-select-tests-based-on-their-name
在test module下有4个测试类,15条测试用例,通过练习来熟悉使用pytest提供的指定用例集合方法。
pytest提供了多种指定测试用例集合的方式:
指定module
指定关键字
指定文件
指定标记的表达式
二、实践
以下实践均在pycharm中进行。
指定module
【Run/Debug Configuration】-【Additional Arguments】参数为空,直接运行即可。
在运行结果中,可以看到,15条测试用例均被执行了。
指定关键字
在运行时,可以通过指定-k参数,指定部分测试用例,以下是-k参数的帮助信息。
例子1:
【Run/Debug Configuration】-【Additional Arguments】-【-k "test_20"】,通过指定关键字,执行了5条与关键字匹配的测试用例
例子2:
【Run/Debug Configuration】-【Additional Arguments】-【-k "not test_20"】,通过指定关键字,忽略了test_20*的测试用例
指定文件
【Run/Debug Configuration】-【Working directory】,设置为test文件的pytest相当于执行了dayByDay目录下的test_xx.py文件。
指定标记的表达式http://i2.51cto.com/images/blog/201711/27/f4ac944da083bce97cc7c30a863fe418.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=[/img]
三、总结
通过pytest提供的指定方式,可以对测试用例进行分拣,灵活的进行选择。同时在构造测试用例的name时,要定义便于标识的keyword。
四、参考资料
[url=https://docs.pytest.org/en/latest/example/markers.html#using-k-expr-to-select-tests-based-on-their-name]https://docs.pytest.org/en/latest/example/markers.html#using-k-expr-to-select-tests-based-on-their-name
相关文章推荐
- 1个练习引发的系列学习之pytest生成测试报告 (三)
- 1个练习引发的系列学习之pytest(一)
- Elastos获取测试用例列表工具--gtci.py(get testcase info)
- Python之使用unittest框架和HTMLTestRunner.py文件实现多个测试用例执行与测试报告生成
- quick-cocos2d-x 学习系列之十四 测试用例
- python实例编写(7)---测试报告与测试套件(多个py文件,1个py文件内多个用例)
- Python单元测试框架之pytest---如何执行测试用例
- IntelliJ IDEA JUnit Generator自动创建测试用例到指定test目录
- 用Python搭建自动化测试框架,我们需要组织用例以及测试执行,这里博主推荐Python的标准库——unittest。 unittest是xUnit系列框架中的一员,如果你了解xUnit的其他成员,那
- 【开发也是好测试系列】(二)——pytest之fixture
- Python 使用 HTMLTestRunner.py 生成测试报告
- VS 2010 测试功能学习(九) - 数据驱动的手工测试用例(@Parameter)(转)
- OPEN(SAP) UI5 学习入门系列之二: 最佳实践练习(上)
- OPEN(SAP) UI5 学习入门系列之二: 最佳实践练习(上)
- 测试用例的评审检查单(Checklist for Test cases)
- One-Click Test Case Binding Tool 一键绑定测试用例(Visual Studio 2012)
- 使用unittest里面的discover()方法组织测试用例
- python pytest测试框架介绍三
- OpenCV学习系列:标定相关程序练习
- appium自动化测试实践之python利用unittest进行测试用例执行的几种方式(转载)