- pytest框架与自动化测试应用
- 房荔枝 梁丽丽编著
- 256字
- 2025-02-25 18:54:08
1.4.4 在PyCharm中配置运行工具
刚才我们执行脚本是通过main方法执行的,也就是通过Python调用pytest的main方法执行。PyCharm支持pytest工具的执行方式,接下来讲解如何配置。
Mac系统中的操作如下:
单击左上角PyCharm→Preferences->Tools->Python Integrated Tools,在Testing的Default test runner中选择pytest。
具体配置如图1-5所示,不同版本可能稍有差别。

图1-5 在Mac系统的PyCharm中配置pytest执行方式
注意:配置完成后有些功能需要重启计算机才能生效。
Windows系统下的配置如图1-6所示,单击File→Setting→Tools Python Intergrated Tools,在Default test runner中选择py.test,单击OK或Apply按钮保存。

图1-6 在Windows系统的PyCharm中配置pytest执行方式
配置完成后,执行方式可以很灵活。既可以通过main方法执行,还可以通过pytest直接执行。