I am writing unit tests in Python for the first time, for a Django application. I ran into a problem. To test specific functionality, I need to change the value of one of the application settings. Here is 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 META_LISTS value so that the new value is used when creating the Document object. Corresponding imports ...
# tests.py from mango.models import Document import mango.settings # models.py from mango.settings import *
If I understood correctly, since models.py already imported names from mango.settings , changing the value of META_LISTS inside mango.settings will not change the value of META_LISTS inside mango.models .
Perhaps - perhaps even that I am completely wrong about this. What is the correct way to change the value of such a “setting” from a test case?
Edit: I did not mention that the models.py file contains vanilla Python classes, not Django models. I definitely need to rename this file!
source share