PyCharm中设置以pytest方式去运行用例
今天整理项目使用unittest+pytest集成allure生成测试报告,运行出现了错误,通过看日志发现原来是用例重复执行了两遍,导致用例之间出现问题。上网查资料发现是我运行项目的时候操作问题。
刚开始我运行项目的时候直接在run_test.py文件中右击,Run 'run_test',这种运行方式运行使用pytest运行用例的方式是不正确的,不建议使用。
![](https://img2020.cnblogs.com/blog/1895590/202004/1895590-20200417145949483-286680286.png)
正确方式是设置run_test.py文件以pytest方式去运行用例
1、File ==>> Settings
3、把里面的 Default test runner 更改为 pytest
![](https://img2020.cnblogs.com/blog/1895590/202004/1895590-20200417150452387-1148997728.png)
4、右上角选择 Edit Configuration 点击
![](https://img2020.cnblogs.com/blog/1895590/202004/1895590-20200417150636947-775481438.png)
5、点击 +,选择Python tests,选择pytest
![](https://img2020.cnblogs.com/blog/1895590/202004/1895590-20200417150901071-1716458560.png)
6、选择pytes启动文件路径,我的是 run_test.py
7、选择Python版本
![](https://img2020.cnblogs.com/blog/1895590/202004/1895590-20200417151200002-460503672.png)
8、运行的时候,右上角选择 pytest in run_test.py ,然后点击右边的按钮启动即可
![](https://img2020.cnblogs.com/blog/1895590/202004/1895590-20200417151353731-1520937413.png)
这样设置后,启动的时候就不会出现重复执行用例的问题了。