ModuleNotFoundError: No module named 'django_project' when I used coverage run manage.py test
See original GitHub issueThe below issue is with Coverage version 5.0a7
When trying to run test for my django project using coverage run manage.py test i get ModuleNotFoundError. This issue kept coming and i thought it was as a result of what was addressed here --> https://stackoverflow.com/questions/50378166/django-coverage-modulenotfounderror-no-module-named-django-extensions
None of the recommendations worked, i downgraded my django version from 3.0 to 2.2 and the problem persisted. This issue was rectified by downgrading to coverage version 4.5
Like i said, i only encountered this issue with coverage version 5.0a7
With the below dependencies, coverage is working as expected
λ pipenv run pip list
Package Version
---------------- -------
asgiref 3.2.3
coverage 4.5
Django 2.2
Pillow 6.2.1
pip 19.3.1
psycopg2 2.8.4
pytz 2019.3
setuptools 41.4.0
sqlparse 0.3.0
wheel 0.33.6
complete error log
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\commands\test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\base.py", line 320, in run_from_argv
parser = self.create_parser(argv[0], argv[1])
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\base.py", line 294, in create_parser
self.add_arguments(parser)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\core\management\commands\test.py", line 44, in add_arguments
test_runner_class = get_runner(settings, self.test_runner)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\test\utils.py", line 301, in get_runner
test_runner_class = test_runner_class or settings.TEST_RUNNER
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\conf\__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\site-packages\django\conf\__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "c:\users\spaceofmiah\.virtualenvs\backend--o8je5ax\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'newproject'
Issue Analytics
- State:
- Created 4 years ago
- Comments:39 (15 by maintainers)
Top Results From Across the Web
Django Coverage ModuleNotFoundError: No module named ...
It could be possible that coverage is not using your virtualenv, but your global python installation instead. Although I'm not sure about that....
Read more >ModuleNotFoundError using coverage.py : r/djangolearning
I ran the command coverage run --source='.' manage.py test minerals in the console, but I'm getting an error: ModuleNotFoundError: No module ...
Read more >4501 (Coverage support for tests) - Django's bug tracker
First off: Making it work for runtests.py and ./manage.py test means that logically I would want to put this code in Django's simple...
Read more >pytest-cov - PyPI
This plugin produces coverage reports. Compared to just using coverage run this plugin does some extras: Subprocess support: you can fork or run...
Read more >Django: Modulenotfounderror: No Module Named - ADocLib
To put it short: this error is caused because Django isn't installed in your environment (virtual environment). I would not recommend installing Django...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For those facing this problem: a work-around seems to be to use “python -m coverage run (etc)” instead of “coverage run (etc)”.
@jpmckinney Thanks, I was finally able to reproduce it myself. Ironically, this turned out to be the important bit:
It wasn’t until I used pyenv and pyenv-virtualenv that the problem appeared for me. Now to work on a fix…