I am using Coverage to measure my test code, but I stuck on a weird problem. I tried the command according to Django Documentation:
coverage run --source='.' manage.py test myapp
But I got this error:
Coverage.py warning: No data was collected. (no-data-collected) Couldn't run 'manage.py' as Python code: SyntaxError: invalid syntax (manage.py, line 16)
It works correctly using python manage.py test myapp.
Here is my manage.py (I didn't modify anything).
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mytestsite.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
What am I missing exactly?
I ran my code and coverage in virtualenv, but I don't think this could be a problem.
ENV:
Python 3.6.8
Django 2.2.3
Coverage 4.5.4
python3 -m virtualenv .envand source, and then I can run coverage.which coveragein virtualenv, it shows/usr/local/bin/coverage.coveragein that virtual env, and it's using the one in/usr/local/bininstead, which is apparently running python version 2.