Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8635457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:58:44+00:00 2026-06-12T09:58:44+00:00

I want to have a single settings.py file that will behave differently when running

  • 0

I want to have a single settings.py file that will behave differently when running the application

./manage.py runserver

and when testing

./manage.py test myapp

So, I can change the test db to sqlite for example, with something like:

if IS_TESTING:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3', 
            'NAME': 'test_db',                      
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2', 
            'NAME': DATABASE_NAME,                      
            'USER': DATABASE_USER,                      
            'PASSWORD': DATABASE_PASS,                  
            'HOST': 'localhost',                      
            'PORT': '5432',                      
        }
    }

I can get this behaviour by changing the manage.py script like this:

if __name__ == "__main__":
    os.environ.setdefault('IS_TESTING', 'false')
    print 'off'
    if sys.argv[1] == 'test':
        print 'on'
        os.environ['IS_TESTING'] = 'true'
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "frespo.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

But I think this is still not good enough, because when I run the tests inside an IDE (PyCharm) it won’t use my custom manage.py file. There has to be a variable for this already inside Django. Do you know where it is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:58:45+00:00Added an answer on June 12, 2026 at 9:58 am

    If you need this condition just for Django unit test purposes, the following line in the settings.py file should work:

    if 'test' in sys.argv:
        DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
        SOUTH_TESTS_MIGRATE = False # if you're using south
    

    This assumes the other standard DATABASES setting is always declared anyway. The above line simply sets the database to sqlite in case of a unit test run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single XML file that I want to index using Lucene.NET. The
I want to have on my site a single select box that will then
I have a single big text file in which I want to process each
I want to have some kind of single list that is initialized in a
Basically I have a single page on my site that I want any php
In my application I have a single nib file. The File's Owner is a
I have a Visual Basic 6.0 application that I want to install for All
I want to have a single lined TextView to show up 3 dots at
I have implemented Single-Sign-On in my iOS 4.3 app successfully. Now I want to
** I want one single list item to have fistname, last name and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.