python-3.x - Persistent ModuleNotFoundError: No module named after setting path to project on Windows OS
问题描述
在我尝试coverage run mytestsuite.py -v
在此代码的终端中运行覆盖范围时:
import unittest
import coverage
import mytestsuite as testSuite
if __name__ == '__main__':
cov = coverage.Coverage()
cov.start()
framework = unittest.TestLoader().loadTestsFromModule(testSuite)
test_result = unittest.TextTestRunner(verbosity=2).run(framework).wasSuccessful()
cov.stop()
cov.save()
print("\nTesting Concluded with result:", test_result)
cov.html_report()
我观察到以下错误: ModuleNotFoundError: No module named 'mysource.py'
其中 mysource.py 使用以下语法导入到 mytestsuite.py 中:
import sourcefolder.mysource as src
如果我在 IDE 中运行 mytestsuite.py,我会看到以下输出:
-------------------------------------------------- -------------------- 在 0.000 秒内运行 0 次测试
OK Coverage.py 警告:未收集数据。(no-data-collected) Traceback(最近一次通话最后一次):文件“C:\Users\Anthem Rukiya\IdeaProjects\DiTTo_YoutubePredictor\test\youtubePredictor_testRunner.py”,第 33 行,在 cov.html_report() 文件“C:\用户\Anthem Rukiya\AppData\Local\Programs\Python\Python39\lib\site-packages\coverage\control.py",第 972 行,在 html_report 返回reporter.report(morfs) 文件“C:\Users\Anthem Rukiya\ AppData\Local\Programs\Python\Python39\lib\site-packages\coverage\html.py”,第 241 行,在报告中为 fr,get_analysis_to_report(self.coverage,morfs)中的分析:文件“C:\Users\Anthem Rukiya\AppData\Local\Programs\Python\Python39\lib\site-packages\coverage\report.py",第 66 行,在 get_analysis_to_report 中引发 CoverageException("No data to report.") coverage.misc。
测试结果:真
进程以退出代码 1 结束
我目前在 IntelliJ 的 Windows 操作系统上运行 Python 3.9.2,并尝试在命令提示符下使用以下命令将我的项目文件设置为 python 路径:set PYTHONPATH%PYTHONPATH%;C:\path_to_my_project_folder
有什么建议么?
解决方案
推荐阅读
- spring - 从 Eclipse 构建 Docker 映像时如何解决错误
- c# - 检测 Shift+单击任务栏以打开新窗口
- apache-flink - Flink Stream 消息是否按顺序发送到下游
- powerbi - How to filter a Table type column by values of an adjacent column
- webpack - Webpack 样式加载器和索引在 IDE 中生成的 sass 代码
- java - 如何调用 searchBook 方法来查找作为 donatedBy 数据属性捐赠的书籍
- powershell - 为什么 PSGallery 的脚本没有 Zone.Identifier 流?
- jenkins - Jenkins 声明式管道嵌入式库包括
- python - 如何在 Python 中共享对象数组
- kotlin - 多个全局范围有问题