解决使用Pytest.main()运行时参数不生效问题
pycharm中使用pytest.main()传入参数执行测试用例时,参数不生效。
·
问题回顾
使用pytest.main('-x')运行时遇到失败用例仍继续执行后面的用例,后改成pytest.main(['222222']),随便写的参数也可以执行用例,发现输入的参数没有生效,但是在cmd中执行pytest.main(['-x'])生效。
前置配置
已经将pycharm默认运行改为pytest,并且右键运行时也是run pytest in XXX

解决办法
点击pycharm右上角的箭头,选择Edit,将用例文件改为普通运行,这样才会使用pytest.main()执行

总结
如果pytest.main()中传入的参数没生效,并且修改了默认运行为pytest,右键运行时默认运行了当前文件的所有用例,因为程序识别到了pytest框架,默认pytest运行,要main主函数运行,需要修改python解释器。
更多推荐


所有评论(0)