Skip to content
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

pytest plugin runs implicitly when django-assets installed #94

Open
tony opened this issue Jan 7, 2019 · 2 comments
Open

pytest plugin runs implicitly when django-assets installed #94

tony opened this issue Jan 7, 2019 · 2 comments

Comments

@tony
Copy link
Contributor

tony commented Jan 7, 2019

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.

tony added a commit to eduflow/django-assets that referenced this issue Jan 7, 2019
This fixes an issue where django-assets would break non-django
pytest fixtures simply because django-assets was installed as
as package.

Fixes miracle2k#94
@miracle2k
Copy link
Owner

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?

@tony
Copy link
Contributor Author

tony commented Jan 7, 2019

@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): 435264e#diff-2188999a0e7833c3726f2360cadccb1a / #33

History: https://github.com/miracle2k/django-assets/commits/master/django_assets/pytest_plugin.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants