pytest:测试两个具有相同根名称的软件包
我有以下情况:
我有一个包含模块xxx.yyy
的软件包y 我有另一个包含模块xxx.zzz的软件包z,他使用了xxx.yyy的几个类。
我想为两个软件包都有相同的条目模块名称xxx。
现在,当我在conda env中安装第一个软件包y并试图在开发文件夹中为第二个软件包z运行pytest时,我遇到了一个错误,即“ modulenotfounderror:no模块not nate xxx.yyy”
如果我使用 - iMport-mode Append运行pytest,我找不到xxx.zzz模块。
如果我用xxx1重命名z套件中的xxx模块,则pytest找到了所有模块。
如果我运行ipython,我可以看到已安装的y软件包。
sys.path的输出清楚地表明,y软件包在给定的conda env。
的正确路径中 如果我将Z软件包安装在同一conda env中,则x软件包中的类在z软件包中可见。
肯定的问题在于pytest。有什么想法吗?
I have the following case:
I have a package Y which have module xxx.yyy
I have another package Z which have module xxx.zzz and he use several classes from xxx.yyy.
I want to have for both packages same entry module name xxx.
Now, when I install in conda env the first package Y and trying to run a pytest for the second package Z in a development folder, I got a error that "ModuleNotFoundError: No module named xxx.yyy"
If I run pytest with --import-mode append, I got that xxx.zzz module is not found.
If I rename the xxx module in Z package with xxx1, the pytest found all modules.
If I run ipython I can see the installed Y package.
The output of the sys.path clearly shows that the Y package is in the correct path for the given conda env.
If I install the Z package in the same conda env, the classes from X package are visible in the Z package.
Definitely the problem is in the pytest. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的“ XXX”模块(在两个软件包中)都没有
__ INIT __。py
file。看起来Pytest在它找到__ Init __. Py
的第一个位置中修复了父模块的位置,并且不会再看待。(我只是在这个确切的问题上奋斗了2个小时,最后设法解决了)
Make sure that your "xxx" module (in both packages Y and Z) does not have
__init__.py
file. It looks like pytest fixes the location of the parent module in the first location it finds__init__.py
, and will not look any further.(I just fought this exact problem for 2 hours and finally managed to solve it)