pytest报错ModuleNotFoundError: No module named ‘xxx‘

**错误描述:**执行pytest时报错 ModuleNotFoundError: No module named ‘xxx’
原因就是scripts文件夹里面没有__init__.py文件
解决方法:在scripts文件夹内添加__init__.py空文件夹
加入后运行成功了
init.py 文件的作用是将文件夹变为一个Python模块,Python 中的每个模块的包中,都有__init__.py 文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当出现"ModuleNotFoundError: No module named 'pytest'"的错误时,表示你的Python环境中没有安装pytest模块。你可以按照以下方法解决这个问题: 解决方法1:使用PyCharm配置unittest运行pytest 1. 在PyCharm中,选择菜单栏中的"Run"->"Edit Configurations..."。 2. 在打开的窗口中,选择"Python tests"->"Unittests"。 3. 在"Target"中选择需要运行的unittest文件,并点击"OK"保存配置。 4. 之后,你可以在菜单栏中选择"Run"->"Run 'Unittests'"来运行unittest。 解决方法2:更改PyCharm的默认测试运行工具为unittest 1. 打开PyCharm,选择菜单栏中的"File"->"Settings"。 2. 在弹出的Settings窗口中,选择"Tools"->"Python Integrated Tools"。 3. 在右侧的"Default test runner"下拉框中选择"unittest",然后点击"Apply"和"OK"保存更改。 4. 之后,你可以在菜单栏中选择"Run"->"Run 'Unittests'"来运行unittest。(如果之前已经生成了pytest配置,在"Run"->"Edit Configurations..."中点击减号删除) 解决方法3:安装pytest模块 1. 打开PyCharm,并在菜单栏中选择"File"->"Settings"。 2. 在弹出的Settings窗口中,选择"Project"->"Python Interpreter"。 3. 右侧列表中找到pytest,点击"+"按钮进行安装。 4. 安装完成后,你应该可以正常使用pytest模块来运行你的测试。 以上是解决"ModuleNotFoundError: No module named 'pytest'"错误的几种方法,你可以根据自己的情况选择适合的方法进行尝试。希望对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [自动化测试python 3.6+pycharm 2018+selenium +unittest和pytest ](https://download.csdn.net/download/XG_17_38241417116/85236217)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Pycharm运行unittest报错ModuleNotFoundError: No module namedpytest‘解决](https://blog.csdn.net/Zhou_ZiZi/article/details/130591116)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [pytest报错ModuleNotFoundError: No module namedpytest](https://blog.csdn.net/WXY111MAO/article/details/131583218)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值