Settings fixture + Celery #46

Closed
dbrgn opened this Issue Jul 11, 2013 · 6 comments

Comments

Projects
None yet
3 participants

dbrgn commented Jul 11, 2013

I'm trying to update the settings for Celery using the settings fixture (CELERY_ALWAYS_EAGER=True). But somehow celery fetches its settings before I get to the point where I update them, so changing the settings fixture has no effect.

This used to work with the Django test class: https://docs.djangoproject.com/en/dev/topics/testing/overview/#overriding-settings

Is there a fix or workaround to this problem?

Owner

pelme commented Jul 14, 2013

Settings are tricky. :(

Django's override_settings does things in a slightly different way than the settings fixture.

It sets the _wrapped attribute on django.conf.settings. It also sends the setting_changed signal. I guess the most reliable way of doing this would be to use django's override_settings internally for the settings fixture, rather than just changing attributes on settings as is done now.

dbrgn commented Jul 14, 2013

Yeah, I guess that would work better, because it would also continue to work when the internal implementation of override_settings changes.

dbrgn commented Jul 23, 2013

What's the status of this? Do you think it would be easy to fix?

brianz commented Feb 15, 2014

This is an old thread, but if you're ok with updating this setting for the entirety of your tests you can do:

# conftest.py

from django.conf import settings

def pytest_configure(config):
    setattr(settings, 'CELERY_ALWAYS_EAGER', True)

I'm using this and it works well so far.

dbrgn commented Feb 15, 2014

@brianz Thanks, looks like a nice workaround. Getting the fixture to work would be even better though :)

@pelme pelme added a commit that referenced this issue Dec 28, 2014

@pelme pelme Fixed #46 - improve the settings fixture.
When changing/deleting a setting, the
django.test.signals.setting_changed fixture will be sent, just like
Django's override_settings decorator.

Refs #93, #136.
e723596
Owner

pelme commented Jul 25, 2015

I'm closing this in favor of #136 which tracks the improvements to the settings fixture.

pelme closed this Jul 25, 2015

@syphar syphar pushed a commit to syphar/pytest-django that referenced this issue Apr 1, 2016

@pelme pelme + Denis Cornehl Fixed #46 - improve the settings fixture.
When changing/deleting a setting, the
django.test.signals.setting_changed fixture will be sent, just like
Django's override_settings decorator.

Refs #93, #136.
a1bf598

@syphar syphar pushed a commit to syphar/pytest-django that referenced this issue Apr 1, 2016

Denis Cornehl Fixed #136 - fix the settings fixture for certain settings.
When changing/deleting a setting, the
django.test.signals.setting_changed fixture will be sent, just like
Django's override_settings decorator.

Refs #93, #46.
80ecf91

@syphar syphar pushed a commit to syphar/pytest-django that referenced this issue Apr 2, 2016

Denis Cornehl Fixed #136 - fix the settings fixture for certain settings.
When changing/deleting a setting, the
django.test.signals.setting_changed fixture will be sent, just like
Django's override_settings decorator.

Refs #93, #46.
e0642a9

@syphar syphar pushed a commit to syphar/pytest-django that referenced this issue Apr 2, 2016

Denis Cornehl Fixed #136 - fix the settings fixture for certain settings.
When changing/deleting a setting, the
django.test.signals.setting_changed fixture will be sent, just like
Django's override_settings decorator.

Refs #93, #46.
a124359

@syphar syphar pushed a commit to syphar/pytest-django that referenced this issue Apr 3, 2016

Denis Cornehl Fixed #136 - fix the settings fixture for certain settings.
When changing/deleting a setting, the
django.test.signals.setting_changed fixture will be sent, just like
Django's override_settings decorator.

Refs #93, #46.
485590c

@syphar syphar pushed a commit to syphar/pytest-django that referenced this issue Apr 4, 2016

Denis Cornehl Fixed #136 - fix the settings fixture for certain settings.
When changing/deleting a setting, the
django.test.signals.setting_changed fixture will be sent, just like
Django's override_settings decorator.

Refs #93, #46.
5d5a309
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment