pytest:测试两个具有相同根名称的软件包

发布于 2025-01-27 12:36:28 字数 478 浏览 2 评论 0原文

我有以下情况:
我有一个包含模块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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ま昔日黯然 2025-02-03 12:36:28

确保您的“ 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文