当前位置:网站首页>UnitTest中的Path must be within the project 问题
UnitTest中的Path must be within the project 问题
2022-08-10 19:01:00 【觅梦_feng】
目前在代码中有如下结构:
discover = unittest.defaultTestLoader.discover(test_dir, pattern='Case*.py')
if runType.find("main") >= 0 :
#此处说明是通过执行器启动的单个用例测试,需生成单个用例的测试套件
dirList = runType.split("\\")
index = len(dirList)
testClassName = dirList[index -1 ]
#由于可能传入不同地址的测试用例 这里需要动态生成测试用例目录地址
start_index = dirList.index("main") + 1
test_dir = './'
for i in range(start_index, index - 1) :
test_dir += dirList[i] + '/'
print test_dir
discover = unittest.defaultTestLoader.discover(test_dir, pattern=testClassName)
也就是说 代码开始时需要生成一个 discover 给UnitTest进行run,之后由于不同的测试目的需要运行不同文件夹下的用例 这样就需要再更新一个 discover
运行时实际会报错Path must be within the project
根据代码字面意思 _relpath.startswith(‘…’) 就会报错,但是同样的两次调用为啥会有这样的问题呢?
查看了下discover的代码逻辑发现
unitTest中的 discover 第三个参数 top_level_dir 第一次运行时如果为None 会取当前传入的start_dir所在路径为 top_level_dir
而这个top_level_dir会作为self的参数保存下来,这样第二次运行时 top_level_dir实际取的是上一次的路径,直接影响到了下一次的运行
因此规避此问题的方法
1 要么在一次运行过程中只调用一次 discover
2 如果一定要调用两次,第二次需要手动将 top_level_dir这个参数传给discover方法,这样才能运行不同文件夹下的用例
即修改为
discover = unittest.defaultTestLoader.discover(test_dir, pattern=testClassName, top_level_dir = self.common.getMainPath())
边栏推荐
- 网站架构探测&chrome插件用于信息收集
- 【LeetCode】42、接雨水
- [教你做小游戏] 斗地主的手牌,如何布局?看25万粉游戏区UP主怎么说
- 状态压缩dp蒙德里安的梦想
- 弘玑Cyclone与风变科技达成战略合作:优势互补聚焦数字化人才培养
- 产品思维训练 | 新用户从注册到绑卡流失率很高是什么原因?
- redis.exceptions.DataError: Invalid input of type: ‘dict‘. Convert to a byte, string or number first
- PG中的Index-Only Scans解密
- 3D Game Modeling Learning Route
- Today's bug, click on the bug that the Windows dynamic wallpaper disappears in the win10 taskbar, and no solution has been found yet.
猜你喜欢

FEMRL: A Framework for Large-Scale Privacy-Preserving Linkage of Patients’ Electronic Health Rec论文总结

「POJ 3666」Making the Grade 题解(两种做法)

MSE 治理中心重磅升级-流量治理、数据库治理、同 AZ 优先

【Knowledge Sharing】What is SEI in the field of audio and video development?

QoS服务质量七交换机拥塞管理
[Go WebSocket] 你的第一个Go WebSocket服务: echo server

FPGA:生成固化文件(将代码固化到板子上面)

DefaultSelectStrategy NIOEventLoop执行策略

MySQL安装步骤
We used 48h to co-create a web game: Dice Crush, to participate in international competitions
随机推荐
flask装饰器版登录、session
pip3升级到22.2.2
【LeetCode】42、接雨水
ARouter使用自定义注解处理器,自动生成跳转Activity的代码,避免手动填写和管理path
今日份bug,点击win10任务栏视窗动态壁纸消失的bug,暂未发现解决方法。
Modern Privacy-Preserving Record Linkage Techniques: An Overview论文总结
常量
pytorch使用Dataloader加载自己的数据集train_X和train_Y
NPDP|传统行业产品经理如何进行能力提升?
阿里云贾朝辉:云 XR 平台支持彼真科技呈现国风科幻虚拟演唱会
JVM内存和垃圾回收-11.执行引擎
「POJ 3666」Making the Grade 题解(两种做法)
Redis persistence mechanism
弘玑Cyclone与风变科技达成战略合作:优势互补聚焦数字化人才培养
杭电多校七 1003-Counting Stickmen(组合数学)
剑指 Offer 27. 二叉树的镜像(翻转二叉树)
API 网关的功能
Keras深度学习实战(17)——使用U-Net架构进行图像分割
flask的配置文件
[Teach you how to do mini-games] How to lay out the hands of Dou Dizhu?See what the UP master of the 250,000 fan game area has to say