I am trying to run coverage on a django project inside of a virtual environment and am having some issues with ModuleNotFoundError
. As per this answer I have installed coverage inside of the virtual environment but am finding that different python interpeter are being used with coverage compared to when running the file with python manually.
When running python manage.py test
the output is:
(env) λ python manage.py test
C:\Users\omarh\Projects\hive\hive-proj\env\Scripts\python.exe
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
where the first line is the result of print(sys.executable)
However when running coverage run manage.py test
with coverage 5.0.1 I get:
(env) λ coverage run manage.py test
c:\users\omarh\projects\hive\hive-proj\env\scripts\python3.exe
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "c:\users\omarh\projects\hive\hive-proj\env\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "c:\users\omarh\projects\hive\hive-proj\env\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\omarh\projects\hive\hive-proj\env\lib\site-packages\django\core\management\commands\test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "c:\users\omarh\projects\hive\hive-proj\env\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\omarh\projects\hive\hive-proj\env\lib\site-packages\django\core\management\base.py", line 294, in create_parser
self.add_arguments(parser)
File "c:\users\omarh\projects\hive\hive-proj\env\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\omarh\projects\hive\hive-proj\env\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\omarh\projects\hive\hive-proj\env\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
self._setup(name)
File "c:\users\omarh\projects\hive\hive-proj\env\lib\site-packages\django\conf\__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "c:\users\omarh\projects\hive\hive-proj\env\lib\site-packages\django\conf\__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "c:\users\omarh\projects\hive\hive-proj\env\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'hive'
the result of running python
and python3
in the venv give an indentical response of:
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
and running python3 manage.py test
is successful.
Running with coverage 3.6 installed instead is also successful however that errors with:
Exception: Couldn't find chunk @ 330
when trying coverage html
Any ideas about why this is happening with Coverage 5.0 and how to fix it? Or how to get Coverage 3.6 to build the HTML report?