Structuring your project guide leads to a ModuleNotFoundError in the tests module
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- documentation
Research direction
Start with the linked “Test Suite” section and reproduce the reported command using samplemod/tests/test_basic.py. Trace how the test file is invoked and how its relative import is resolved, then update the guide so the documented setup and execution path work without the reported ModuleNotFoundError.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Batchfile
- Stars
- 29.8k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from realpython/python-guide
-
Page 404 error Open
Difficulty 1/5 Under an hour Newbie friendliness 65/100
realpython/python-guide#1104 · 2 comments ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 62/100
realpython/python-guide#327 ·
-
PyZMQ improvements Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
realpython/python-guide#326 · 5 comments ·
-
@alex Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
realpython/python-guide#1194 ·
-
Development Team SAP Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
realpython/python-guide#1192 ·
All issues in realpython/python-guide
Similar issues
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
A11y ♿️
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Link Checker Report Openautomated issue report
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
documentation improve or update documentation priority/low triage
Difficulty 2/5 Half a day Newbie friendliness 86/100
warpdotdev/docs#782 · 1 comment ·