pytest的时候脚本报错AttributeError: module ‘xxx‘ has no attribute ‘xxx‘ 解决方法

ex:

modfile = mod.file
E AttributeError: module ‘array’ has no attribute ‘file

解决:

  • py脚本的文件名,不要与python预留字,模块名等相同,所以要修改文件名

  • (如果第一步还不行)删除该库的.pyc文件(因为每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;


版权声明:本文为eebaicai原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。