当前位置: 代码迷 >> 综合 >> 解决pytest在pycharm中报错:NameError: name 'pytest' is not defined
  详细解决方案

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

热度:125   发布时间:2023-09-07 08:26:10.0

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/UITraceback (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 definedProcess finished with exit code 1Empty suite

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

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

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

  相关解决方案