pycharm运行pytest

时间:2023-03-09 06:10:47
pycharm运行pytest

pycharm运行三种方式

1.以xx.py脚本方式直接执行,当写的代码里面没用到unittest和pytest框架时,并且脚本名称不是以test_开头命名的,此时pycharm会以xx.py脚本方式运行

2.当脚本命名为test_xx.py时,用到unittest框架,此时运行代码,pycharm会自动识别到以unittest方式运行

3.以pytest方式运行,需要改该工程设置默认的运行器:file->Setting->Tools->Python Integrated Tools->项目名称->Default test runner->选择py.test

如果修改py.test不生效:

1、pycharm的右上角的 Edit Configurations

2、删除Python tests下面的脚本文件

3、选择Defaults—Python tests—py.test,在右边的配置里选择要运行的脚本文件的路径,点击OK保存

4、可以使用run py.test 运行了