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 7549823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:03:07+00:00 2026-05-30T10:03:07+00:00

I want to test a small reusable app which comes with its own settings

  • 0

I want to test a small reusable app which comes with its own settings module. Global (project) settings are accessed inside app’s settings to support variables’ overriding, e.g.

# in <my_app>/settings.py
from django.conf import settings
MY_SETTING_VAR = getattr(settings, 'MY_OVERRIDDEN_VAR', False)

When I run tests with manage.py test myapp I get the following:

ImportError: Settings cannot be imported, because environment
variable DJANGO_SETTINGS_MODULE is undefined.

What is the right way to run tests in this case?

  • 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-05-30T10:03:09+00:00Added an answer on May 30, 2026 at 10:03 am

    I’m not sure, i tested exactly what you posted and it works for me:

    <<< 12:18.25 Fri Feb 24 2012!~/testproject 
    <<< jpic@germaine!10019 env
    >>> ./manage.py test testapp                   
    Creating test database for alias 'default'...
    Destroying old test database 'default'...
    .
    ----------------------------------------------------------------------
    Ran 1 test in 0.000s
    
    OK
    Destroying test database for alias 'default'...
    <<< 12:18.27 Fri Feb 24 2012!~/testproject 
    <<< jpic@germaine!10020 env
    >>> cat testapp/tests.py
    from django.test import TestCase
    
    from .settings import *
    
    class SomeTestCase(TestCase):
        def testSomething(self):
            self.assertEqual(MY_SETTING_VAR, 'default')
    <<< 12:18.30 Fri Feb 24 2012!~/testproject 
    <<< jpic@germaine!10021 env
    >>> cat testapp/settings.py
    from django.conf import settings
    MY_SETTING_VAR = getattr(settings, 'MY_OVERRIDDEN_VAR', 'default')
    

    You want to make sure your actual code matches this working code.

    It’s better for an app to include a dummy project that demonstrates the app or at least allows testing. For example:

    <<< 12:42.56 Fri Feb 24 2012!~/testproject/testapp 
    <<< jpic@germaine!10034 E:1 env
    >>> pip install -e git+git@github.com:subsume/django-subscription.git#egg=sub
    Obtaining sub from git+git@github.com:subsume/django-subscription.git#egg=sub
      Cloning git@github.com:subsume/django-subscription.git to /home/jpic/env/src/sub
      Running setup.py egg_info for package sub
    
    Installing collected packages: sub
      Running setup.py develop for sub
    
        Creating /home/jpic/env/lib/python2.7/site-packages/django-subscription.egg-link (link to .)
        Removing django-subscription 0.0 from easy-install.pth file
        Adding django-subscription 0.1 to easy-install.pth file
    
        Installed /home/jpic/env/src/sub
    Successfully installed sub
    Cleaning up...
    <<< 12:43.08 Fri Feb 24 2012!~/testproject/testapp 
    <<< jpic@germaine!10035 env
    <<< 12:43.11 Fri Feb 24 2012!~/testproject/testapp 
    <<< jpic@germaine!10035 env
    >>> cd ../../env/src/sub
    <<< 12:43.15 Fri Feb 24 2012!~/env/src/sub 
    <<< jpic@germaine!10036 G:master env
    >>> ls
    django_subscription.egg-info  docs  README  setup.py  subscription  subscription_test_project
    <<< 12:43.16 Fri Feb 24 2012!~/env/src/sub 
    <<< jpic@germaine!10037 G:master env
    >>> cd subscription_test_project 
    <<< 12:43.20 Fri Feb 24 2012!~/env/src/sub/subscription_test_project 
    <<< jpic@germaine!10038 G:master env
    >>> ./manage.py test subscription
    Creating test database for alias 'default'...
    ........
    ----------------------------------------------------------------------
    Ran 8 tests in 0.012s
    
    OK
    Destroying test database for alias 'default'...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a small hello world test app in Silverlight which i want to
I have a small program I want to execute to test something #include <map>
I have a small question. How can I test an application which uses the
I am just testing a small program that I want to test. I am
I've implemented a small test which uses celery for message queueing and I just
Earlier today I wrote a small test app for iteratees that composed an iteratee
I Developed a small Application in C#. I want to test my application with
I want to store some test data for a FlexUnit test in small XML
I have a posts controller on a small test website I'm making. I want
I have created a small test app. It creates a new company and a

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.