-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing DJANGO_SETTINGS_MODULE #18
Comments
Can you show the complete error report with traceback? |
Sure. Actually from the traceback it looks more like django-coverage-plugin wants the use settings before Traceback (most recent call last):
File "/my/project/.tox/py35-django18/bin/coverage", line 11, in <module>
sys.exit(main())
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/coverage/cmdline.py", line 741, in main
status = CoverageScript().command_line(argv)
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/coverage/cmdline.py", line 481, in command_line
return self.do_run(options, args)
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/coverage/cmdline.py", line 610, in do_run
self.coverage.erase()
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/coverage/control.py", line 709, in erase
self._init()
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/coverage/control.py", line 218, in _init
self.plugins = Plugins.load_plugins(self.config.plugins, self.config, self.debug)
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/coverage/plugin_support.py", line 49, in load_plugins
coverage_init(plugins, options)
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/django_coverage_plugin/__init__.py", line 11, in coverage_init
reg.add_file_tracer(DjangoTemplatePlugin())
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/django_coverage_plugin/plugin.py", line 122, in __init__
check_debug()
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/django_coverage_plugin/plugin.py", line 52, in check_debug
templates = getattr(settings, 'TEMPLATES', [])
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/my/project/.tox/py35-django18/lib/python3.5/site-packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. |
Note that this worked in 1.1 and broke in 1.2, I can bisect the commit for you if you want |
@jonashaag more details about how reproduce this, or which commit it was, would be great. |
Just use |
Bump |
@jonashaag Did you manage to identify the exact commit that causes the error? |
@keimlink Yes but I don't remember which one it was, you can simply run |
bisect points at 0085fb8 |
I'll be able to jump into this more easily with a zipfile or specific instructions about how to reproduce it. |
Steps to reproduce:
|
Actually, it works fine if you run from the directory where manage.py is located. I think that is expected. You should always run @jonashaag: does it work if you cd into |
Eh, sorry. My comment above about having to run But at least I found out that the current directory has something to do with it. Happy debugging ;) |
The working directory is a red herring: that's because there's no .coveragerc in the subdirectory. If you copy it there, the failure happens in either directory. I think the fix is to move the plugin's access of settings to later, when it is actually needed. |
Just chiming in to say I fixed this same bug when using If anyone's trying to find a better solution, I can tell you that you need to find a way to raise this error after |
Some programs don't need settings. If we check early, then our plugin will fail where the original program would not. Now we check later, when we know that we will actually be involved.
This is fixed as of commit fdb0892 |
I'll make a new release. If you could test it out, that would be great. |
Thanks! With my config, fdb0892 works but still doesn't log the error when template debugging is off. Nothing in the coverage debug log either. For the record I'm using:
I'm not sure which of these is responsible for eating the exception. |
@emmalemma Can you show me some output? When I run a project without a debug setting, I get this:
|
Sure. I can reproduce this with a minimal pytest setup:
create
edit settings.py:
Demonstrate it works:
Then set
If I run the same thing on emmalemma/django_coverage_plugin@e083da1, with
Presumably, the check in fdb0892 is working properly, and killing the plugin; it's just not getting to stderr or stopping pytest. The original issue is probably fixed by this patch. There might not be anything for the plugin to do about my problem, since it's probably something in pytest or pytest-cov. Or there might a configuration somewhere. I haven't spent much time hunting since the actual plugin is working just fine for me. |
@emmalemma thanks for the detailed steps! I'm looking into what is hiding the exception. BTW: |
Hah, whoops! I only use zsh, forgot that would happen in bash. I guess I need to use Thanks for taking the time to look into this, and especially thanks for your work on the plugin in the first place. |
I opened #25 to deal with the invisible exception. |
I was getting the following error:
I thought I had the setting enabled, but here's the thing:
DEBUG = True
TEMPLATES = [
{
...
'OPTIONS': {
'debug': DEBUG,
},
},
] Error is gone 🎉 |
With empty
.coveragerc
:With django-coverage-plugin in
.coveragerc
:manage.py
is unmodified (generated by Django).The text was updated successfully, but these errors were encountered: