pycharm使用unittest框架报错ImportError: Start directory is not importable: './xxx文件路径'

一、问题描述

在使用unittest进行测试用例编写时,代码没有问题,运行时报错ImportError: Start directory is not importable: './xxx文件路径'

  • 示例代码

  • 运行结果

二、分析问题

  • 将test_dir路径替换为绝对路径运行,运行成功

  • 即认为pycharm中无法识别相对路径,Google显示添加_ init _.py文件可以解决,尝试后无果

三、解决办法

  • 打开 edit configurations

  • 将working directory更改到根目录,运行即可成功

四、总结

第一次写博客,还有很多需要改进的地方,如果有缘看见可以反馈哦。

posted @ 2021-03-18 10:47  测开小白菜  阅读(999)  评论(1编辑  收藏  举报