Breaking running of coverage when enabled
See original GitHub issueFirst, thanks for this great plug-in! Iāve found it quite useful for testing some of the logic in my templates. š
I know this used to work in my project, but Iām not sure when it broke. (I donāt think this has updated in a while, it could have been a Django update that broke this?)
My project is using Django 1.10.4, coverage 4.3.1, django-coverage-plugin 1.3.1. (I also tried with coverage 4.2, that exhibited the same behavior.)
While running with this Iām getting a stack trace:
/vagrant$ coverage run manage.py test
Coverage.py warning: Disabling plugin 'django_coverage_plugin.DjangoTemplatePlugin' due to an exception:
Traceback (most recent call last):
File "/usr/local/venv/local/lib/python2.7/site-packages/coverage/control.py", line 497, in _should_trace_internal
file_tracer = plugin.file_tracer(canonical)
File "/usr/local/venv/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.py", line 154, in file_tracer
check_debug()
File "/usr/local/venv/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.py", line 55, in check_debug
templates = getattr(settings, 'TEMPLATES', [])
File "/usr/local/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/vagrant/my_project/settings.py", line 8, in <module>
from django.contrib.messages import constants as message_constants
File "/usr/local/venv/local/lib/python2.7/site-packages/django/contrib/messages/__init__.py", line 1, in <module>
from django.contrib.messages.api import * # NOQA
File "/usr/local/venv/local/lib/python2.7/site-packages/django/contrib/messages/api.py", line 3, in <module>
from django.http import HttpRequest
File "/usr/local/venv/local/lib/python2.7/site-packages/django/http/__init__.py", line 5, in <module>
from django.http.response import (
File "/usr/local/venv/local/lib/python2.7/site-packages/django/http/response.py", line 13, in <module>
from django.core.serializers.json import DjangoJSONEncoder
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/serializers/base.py", line 4, in <module>
from django.db import models
ImportError: cannot import name models
Traceback (most recent call last):
File "manage.py", line 45, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 316, in execute
settings.INSTALLED_APPS
File "/usr/local/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/vagrant/my_project/settings.py", line 8, in <module>
from django.contrib.messages import constants as message_constants
File "/usr/local/venv/local/lib/python2.7/site-packages/django/contrib/messages/__init__.py", line 1, in <module>
from django.contrib.messages.api import * # NOQA
File "/usr/local/venv/local/lib/python2.7/site-packages/django/contrib/messages/api.py", line 1, in <module>
from django.contrib.messages import constants
ImportError: cannot import name constants
This seems to be because Iām importing django.contrib.messages.constants
in my settings file, note that if I remove this line I get other errors about importing. This seems related to loading of Django settings before Django is configured (see https://github.com/nedbat/django_coverage_plugin/issues/28#issuecomment-243723099), but with much worse consequences.
Let me know if there is anything I can do to help confirm my suspicion or narrow this down! Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Hi, this is a chicken-and-egg problem with settings configuration-and template loading that I think is masked by the the django_coverage_plugin test environment (initialization order stuff is always hard to test).
Iāve got a reproducible case and Iām working on it - but itās prioritized behind a couple of other commitments. Hopefully this weekend for a fix to this problem and later Iāll update the dj-c-p test framework to include a stand-alone test_project to provide for some cleaner integration tests.
pam
On Tue, Jan 17, 2017 at 9:49 AM, Patrick Cloke notifications@github.com wrote:
ā Pamela McAāNulty Senior Director, Software Engineering 75 Sidney Street, Suite 550A Cambridge, MA 02139 direct: 617-245-2576 office: 617-225-9000 www.addgene.org
Love Addgene? Follow us: Facebook https://www.facebook.com/addgene | Twitter https://twitter.com/Addgene | LinkedIn https://www.linkedin.com/company/addgene | Blog http://blog.addgene.org/
š„ That worked! Seems like this was fixed by #33. Thanks so much for the help!