python - 子目录中的 __init__.py 文件是否会触发父目录中的 __init__.py 文件?(Python 3.9)
问题描述
我的 Python 项目目前正遇到我的依赖项存在冲突的问题。function_a.py
在我为代码( in file_a.py
)中的特定函数编写完测试之后,我想稍后解决这个问题。
当我在此目录 ( ) 中的测试文件上显式运行 pytest 时,pytest test_a.py
一切都很好,我的测试通过了。但是,如果我将__init__.py
文件添加到此目录,则由于依赖项之间的冲突(__init__.py
在父目录的文件中导入),我的代码会出错。
作品:
- parent_directory
- other_files.py
- __init__.py
- child_directory
- file_a.py
- test_a.py
不工作:
- parent_directory
- other_files.py
- __init__.py
- child_directory
- file_a.py
- test_a.py
- __init__.py
为什么__init__.py
child_directory 中的 会导致__init__.py
parent_directory 中的我的 other 被执行?
解决方案
推荐阅读
- python - AttributeError:无法导入 keras 和分割模型
- azure - 使用 WAFV2 Azure App Gateway 使用多个基本侦听器时无法更新 SSL 证书
- postgresql - Postgres jsonb_path_query 按长度过滤子数组
- python-3.x - Golem Task 响应运行时错误 2,无法确定原因
- streamsets - Google 云存储写入的输出中添加了倒置感叹号
- mysql - MySQL 非英文字符为?
- java - IntelliJ 找不到已安装的软件包
- azure - 筛选 Azure 磁盘资源的名称
- python - 如何在python中选择不在html上的隐藏元素
- c# - 使用 CosmosDB 作为 SignalR 池