解决pytest在pycharm中报错:NameError: name 'pytest' is not defined

一笑奈何 提交于 2020-02-06 10:43:53

pycharm CE 2019.2中配置pytest环境时,遇到了如下报错:

esting started at 上午11:32 ...
/usr/local/bin/python3.7 "/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_pytest_runner.py" --path /Users/tu/Desktop/UI/test_q.py
Launching pytest with arguments /Users/tu/Desktop/UI/test_q.py in /Users/tu/Desktop/UI

Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_pytest_runner.py", line 45, in <module>
    pytest.main(args, plugins_to_load)
NameError: name 'pytest' is not defined

Process finished with exit code 1

Empty suite

参考其他相似问题的解决办法,检查以下内容:
1.查看导入模块 import pytest
2.查看pytest安装路径,是否在python3路径下
3.查看解释器版本是否为python3.7

检查以上三项都正常,但依然报错。

然后再详细的分析了报错内容,打开/Applications/PyCharm CE.app/Contents/helpers/pycharm/_jb_pytest_runner.py 文件,自己导入pytest模块import pytest
再次运行,成功

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!