Structuring your project guide leads to a ModuleNotFoundError in the tests module
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 42/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
从链接的“Test Suite”部分开始,并使用 samplemod/tests/test_basic.py 重现报告中的命令。跟踪测试文件的调用方式以及其相对导入的解析方式,然后更新指南,使文档中说明的设置和执行路径能够正常工作,且不会出现报告中的 ModuleNotFoundError。
由索引模型根据 Issue 内容生成。
描述
Following this section, adding from .context import sample in my tests module gives me the following error: ModuleNotFoundError: No module named '__main__.context'; '__main__' is not a package
I was able to fix it by removing the . from from .context import sample, but I suspect that's not the ideal solution. I know that the from .context import sample is a relative import statement as described in PEP 328, but I just do not understand modules, packages, absolute and relative imports, etc. enough to say what's going on here.
I tried creating ./__init__.py and ./tests/__init__.py files, but that did not help.
Finally, I tried the following:
~> git clone git@github.com:navdeep-G/samplemod.git
~> python3 samplemod/tests/test_basic.py
Traceback (most recent call last):
File "samplemod/tests/test_basic.py", line 3, in <module>
from .context import sample
ModuleNotFoundError: No module named '__main__.context'; '__main__' is not a package
I'm not alone in hitting this issue. @rileyweber13 originally reported this problem a year ago.
- 主要语言
- Batchfile
- 星标
- 29.8k
- 派生
- 5.9k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
realpython/python-guide 的其他 Issue
-
Page 404 error 未关闭
难度 1/5 1 小时以内 新手友好度 65/100
realpython/python-guide#1104 · 2 条评论 ·
-
难度 1/5 1-3 小时 新手友好度 62/100
realpython/python-guide#327 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
realpython/python-guide#326 · 5 条评论 ·
-
@alex 未关闭
难度 5/5 一周以上 新手友好度 10/100
realpython/python-guide#1194 ·
-
难度 5/5 一周以上 新手友好度 10/100
realpython/python-guide#1192 ·
查看 realpython/python-guide 的全部 Issue
相似的 Issue
-
automated issue report
难度 2/5 1-3 小时 新手友好度 78/100
felladrin/uo-is-not-dead#176 · 1 条评论 ·
-
documentation
难度 1/5 1 小时以内 新手友好度 78/100
Qiskit/qiskit-addon-sqd#376 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Seeed-Studio/wiki-documents#5655 · 2 条评论 ·
-
type:content-error
难度 2/5 1-3 小时 新手友好度 72/100
stephrobert/blog-roadmap#15 ·
-
难度 2/5 1-3 小时 新手友好度 82/100