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.

Q: overriding settings

See original GitHub issue

Is there a recommended way to override settings for the live server? Normally I’d use @override_settings(DEBUG=True) so I can see tracebacks while debugging, but had to settle for this:

def before_scenario(context, scenario):
    if "DEBUG" in scenario.tags:
        from django.conf import settings
        settings.DEBUG = True

(and corresponding after_scenario())

It works, but is there a better way?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
graingertcommented, Aug 2, 2016

@farcepest are you still alive?

0reactions
pydolancommented, Mar 21, 2019

It makes sense to me for settings to work similar to how behave-django allows fixture loading, where behave-django would support both of the following options:

Interface:

Option 1: in before_scenario

In this example, we override settings for a particular scenario. Since a new test class is instantiated for each scenario, teardown is automatic:

def before_scenario(context, scenario):
    if scenario.name == 'User login with valid credentials':
        context.override_settings = {'DEBUG': True, 'LOGIN_URL': '/login/here'}

Option 2: via decorator on step functions

In this example, we define a Given Step that uses the behave_django.decorators.override_settings decorator, which behave-django would use to override django’s settings for the entire scenario:

  • Step function:
    @override_settings(DEBUG=True, LOGIN_URL='/login/sso')
    @given('I enable debugging and login with SSO')
    def step_impl(context):
        pass
    
  • Gherkin file:
    Scenario: User login with valid credentials
        Given I enable debugging and login with SSO
        When I login with "test" and "test"
        Then I see content "Welcome"
    

Implementation:

I’m assuming that in the code where behave-django adds fixtures to the TestCase class, the django settings can also be overwritten. This can possibly be done with django.test.utils.override_settings, either using the class as a context, or mimicking what the decorate_class method is doing. Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Override Default Statistical Testing Settings
By default, Q automatically takes into account the structure of the data when determining how to perform tests.
Read more >
Overriding Chrome settings in Chrome Extensions
Settings overrides are a way for extensions to override selected Chrome settings. The API is available on Windows in all current versions of ......
Read more >
how to auto override force dark mode in android Q | XDA Forums
First, turn off regular dark mode (if enabled) and reboot your cell phone. Then, toggle the override-dark-mode option in developer settings and ...
Read more >
Overriding settings in Django when used by the models
Finally, avoid aliasing your settings as module-level constants as override_settings() won't work on such values since they are only evaluated the first time ......
Read more >
How to Statically Override the Default Settings in jOOQ
… and much more. Your configuration will probably include an explicit Settings instance where you have fine grained, perhaps even per-execution ...
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