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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:11:48+00:00 2026-05-17T03:11:48+00:00

I’m writing unit tests in Python for the first time, for a Django app.

  • 0

I’m writing unit tests in Python for the first time, for a Django app. I’ve struck a problem. In order to test a particular piece of functionality, I need to change the value of one of the app’s settings. Here’s my first attempt:

def test_in_list(self):
    mango.settings.META_LISTS = ('tags',)
    tags = Document(filepath).meta['tags']
    self.assertEqual(tags, [u'Markdown', u'Django', u'Mango'])

What I’m trying to do is change the value of META_LISTS such that the new value is used when the Document object is created. The relevant imports are…

# tests.py
from mango.models import Document
import mango.settings

# models.py
from mango.settings import *

If I’ve understood correctly, since models.py has already imported the names from mango.settings, changing the value of META_LISTS within mango.settings will not alter the value of META_LISTS within mango.models.

It’s possible – likely even – that I’m going about this in completely the wrong way. What’s the correct way to alter the value of such a “setting” from within a test case?

Edit: I failed to mention that the file models.py contains vanilla Python classes rather than Django models. I certainly need to rename this file!

  • 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-17T03:11:48+00:00Added an answer on May 17, 2026 at 3:11 am

    In models.py, use import mango.settings. You can then set a variable in your test code like you would any other:

    mango.settings.foo = 'bar'
    

    A module is a singleton. You can change the values in its namespace from anywhere in your code.

    But this won’t work if you use from mango.settings import *, since that expression copies the values in the module into the current namespace.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I am using Paperclip to handle profile photo uploads in my app. They upload
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.