realpython / realpython/python-guide
Structuring your project guide leads to a ModuleNotFoundError in the tests module
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Batchfile
- Sterne
- 29.8k
- Forks
- 5.9k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit dem verlinkten Abschnitt „Test Suite“ und reproduzieren Sie den gemeldeten Befehl unter Verwendung von samplemod/tests/test_basic.py. Verfolgen Sie, wie die Testdatei aufgerufen wird und wie ihr relativer Import aufgelöst wird, und aktualisieren Sie anschließend den Leitfaden, sodass der dokumentierte Einrichtungs- und Ausführungspfad ohne den gemeldeten ModuleNotFoundError funktioniert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100