realpython / realpython/python-guide
Structuring your project guide leads to a ModuleNotFoundError in the tests module
まだ誰も着手していません。
- 主要言語
- Batchfile
- スター
- 29.8k
- フォーク
- 5.9k
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている「Test Suite」セクションから始め、samplemod/tests/test_basic.py を使って報告されたコマンドを再現してください。テストファイルがどのように呼び出され、その相対インポートがどのように解決されるかを追跡し、報告された ModuleNotFoundError が発生せずに、ドキュメントに記載されたセットアップおよび実行パスが機能するようガイドを更新してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100