pytest plugin runs implicitly when django-assets installed
I am using django-assets on a multi-framework codebase where some tests won't require django.
What will happen is this:
______ ERROR at setup of test_allowed_to_peergrade[B-expired-False-NONE] _______
../../../virtualenv/python3.7.1/lib/python3.7/site-packages/django_assets/pytest_plugin.py:6: in set_django_assets_env
django_assets.env.get_env() # initialise django-assets settings
../../../virtualenv/python3.7.1/lib/python3.7/site-packages/django_assets/env.py:177: in get_env
env = DjangoEnvironment()
../../../virtualenv/python3.7.1/lib/python3.7/site-packages/webassets/env.py:724: in __init__
self.config.setdefault('debug', False)
../../../virtualenv/python3.7.1/lib/python3.7/site-packages/webassets/env.py:63: in setdefault
if not key in self:
../../../virtualenv/python3.7.1/lib/python3.7/site-packages/django_assets/env.py:51: in __contains__
return hasattr(settings, self._transform_key(key))
../../../virtualenv/python3.7.1/lib/python3.7/site-packages/django/conf/__init__.py:57: in __getattr__
self._setup(name)
../../../virtualenv/python3.7.1/lib/python3.7/site-packages/django/conf/__init__.py:42: in _setup
% (desc, ENVIRONMENT_VARIABLE))
E django.core.exceptions.ImproperlyConfigured: Requested setting ASSETS_DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
In my case, django-assets is being pulled in with all pytest tests, since it's autouse=True and attempting to access the settings singleton.
I'm thinking about what the best option would be to handle this - I think the best option would be to hold off autouse=True and let the user add the fixture where and when they need it.
Sounds good. I am wracking my brain trying to figure out what the purpose of this fixture is. It came from a PR from @tomd-aptivate a couple years ago. @tony do you know?
@miracle2k I'm not using pytest+django-assets at the same time, so I can't tell for sure, the original usage of it was to make sure django-assets didn't lose settings (apparently): https://github.com/miracle2k/django-assets/commit/435264eb704ebf1adbfb5d04b4e0e6eceb5c30f0#diff-2188999a0e7833c3726f2360cadccb1a / #33
History: https://github.com/miracle2k/django-assets/commits/master/django_assets/pytest_plugin.py