question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breaking running of coverage when enabled

See original GitHub issue

First, 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:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
PamelaMcommented, Jan 19, 2017

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:

@PamelaM https://github.com/PamelaM First, thanks for taking a look at this! šŸ‘

This seems to have fixed the issue of coverage erroring immediately when running, but unfortunately I don’t seem to have any coverage of the templates! (I can run coverage and get a coverage report, including the template files, but it doesn’t seem to have actually processed these files.)

I’m getting the following warning when I run coverage:

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 476, 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 158, in file_tracer self.debug_checked = check_debug() File ā€œ/usr/local/venv/local/lib/python2.7/site-packages/django_coverage_plugin/plugin.pyā€, line 56, in check_debug if not hasattr(django.template.backends, ā€œdjangoā€): AttributeError: ā€˜module’ object has no attribute ā€˜backends’

I tried this quickly in a Django shell and django.template DOES have an attribute backends. My settings look like:

TEMPLATES = [ { ā€˜BACKEND’: ā€˜django.template.backends.django.DjangoTemplates’, ā€˜DIRS’: [normpath(join(DJANGO_ROOT, ā€˜templates’))], ā€˜APP_DIRS’: True, ā€˜OPTIONS’: { ā€˜context_processors’: [ ā€˜django.contrib.auth.context_processors.auth’, ā€˜django.template.context_processors.debug’, ā€˜django.template.context_processors.i18n’, ā€˜django.template.context_processors.media’, ā€˜django.template.context_processors.static’, ā€˜django.template.context_processors.tz’, ā€˜django.contrib.messages.context_processors.messages’, ā€˜django.template.context_processors.request’,

            # + a few custom ones.
        ],
        'debug': DEBUG,
    },
},

]

Any idea what’s happening here? Thanks again!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nedbat/django_coverage_plugin/issues/29#issuecomment-273188832, or mute the thread https://github.com/notifications/unsubscribe-auth/AAz1vTXlJADqDGl8sfni5c5qyEtNAAJSks5rTNUHgaJpZM4LXn8R .

– 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/

0reactions
clokepcommented, Jan 21, 2017

šŸ’„ That worked! Seems like this was fixed by #33. Thanks so much for the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

If I enroll in the exchange, will that coverage take effect ...
The special enrollment period, in that case, will run for 60 days before and 60 days after the loss of coverage. People in...
Read more >
Does Full Coverage Cover Break-Ins? - WalletHub
Yes, full coverage does cover break-ins. Break-ins are covered by comprehensive car insurance, a main component of a full coverage insuranceĀ ...
Read more >
13.0.0 Release Notes Ā· Issue #684 Ā· hapijs/lab Ā· GitHub
Adjust any coverage threshold percentages in your test run scripts after running version v13.0.0 with coverage enabled. The text was updated successfully, butĀ ......
Read more >
Why millions on Medicaid are at risk of losing coverage ... - NPR
People could lose their coverage if they earn too much or don't provide the information their state needs to verify their income orĀ ......
Read more >
Customize pipeline configuration - GitLab Docs
Set up a coverage regular expression for all jobs you want to include in the overall coverage value. Go to your project and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found