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
-
Add: hunch 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
AbdelStark/awesome-typesafe#104 ·
-
難度 2/5 1-3 小時 新手友好度 65/100
-
A11y ♿️
難度 2/5 1-3 小時 新手友好度 72/100
-
automated issue report
難度 2/5 1-3 小時 新手友好度 85/100
-
documentation improve or update documentation priority/low triage
難度 2/5 半天 新手友好度 86/100
warpdotdev/docs#782 · 1 則留言 ·