Hi Adam,

I was hitting same issue but never got chance to debug it.
If the underneath database support database transactions then isn't that
each test will be treated as a separate transaction and transaction should 
be rolled back
after the test is over to keep the database sane ?

On Wednesday, June 8, 2016 at 1:43:40 AM UTC-7, Derek wrote:
>
> Thanks Adam, I will try that.  I think I have been lax in the use of 
> tearDown.
>
> On Thursday, 2 June 2016 21:47:00 UTC+2, Adam wrote:
>>
>> When I've had that happen before, it's because some previous test changed 
>> something (like a setting value or the site domain) that influenced the 
>> test that failed. To narrow it down, I would run all the tests up to and 
>> including the failed one. That should fail, then I start taking out half 
>> the tests before. If the test still fails, I keep cutting in half until I 
>> can determine which previous test is causing issues. If, after cutting out 
>> tests, the problem test passes, then I need to put back in what I took out 
>> since it was one of those.
>>
>> Once I figure out which previous test it was, I can start removing the 
>> individual tests to finally get to the code causing the problem. Usually, 
>> it's a case that a test changed something and I just have to add in the 
>> teardown function to restore the state of whatever was changed.
>>
>> On Thu, 2016-06-02 at 21:33 +0200, Derek wrote:
>>
>> I have a test that is failing when the file it is in is run as part of 
>> all the other test files by the test runner.
>>
>> If I just run only the file that contains this test -  then it passes.
>>
>> (pass/fail refers to the very last assert in the code below.)
>>
>> I'd appreciate any ideas or insights from anyone who can spot an obvious 
>> mistake - or suggest some options to explore.
>>
>> Thanks
>> Derek
>>
>>
>> # THIS IS AN EXTRACT OF RELEVANT CODE (not all of it...)
>> from django.contrib.messages.storage.fallback import FallbackStorage
>> from django.core.urlresolvers import reverse
>> from django.test import TestCase, Client
>> # ... various app-related imports ...
>>
>>
>> class MockRequest(object):
>>     """No code needed."""
>>     pass
>>
>>
>> REQUEST = MockRequest()
>> # see: https://stackoverflow.com/queI 
>> stions/11938164/why-dont-my-django-\
>> #      unittests-know-that-messagemiddleware-is-installed
>> setattr(REQUEST, 'session', 'session')
>> MESSAGES = FallbackStorage(REQUEST)
>> setattr(REQUEST, '_messages', MESSAGES)
>> setup_test_environment()
>>
>>
>> class PersonAdminTest(TestCase):
>>
>>     def setUp(self):
>>         self.user, password = utils.user_factory(model=None)
>>         self.client = Client()
>>         login_status = self.client.login(username=self.user.email, 
>> password=password)
>>         self.assertEqual(login_status, True)
>>
>>     def test_action_persons_make_unreal(self):
>>         try:
>>             change_url = reverse('admin:persons_realpersons_changelist')
>>         except NoReverseMatch:
>>             change_url = '/admin/persons/realpersons/'
>>             sys.stderr.write('\n   WARNING: Unable to reverse URL! ... ')
>>         response = self.client.get(change_url)
>>         self.assertEqual(response.status_code, 200)
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAF1Wu3MoGgm_dSToObDX9gH7GQJ%3DTZzGLV7RPOiZk4kvV-_Nbg%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CAF1Wu3MoGgm_dSToObDX9gH7GQJ%3DTZzGLV7RPOiZk4kvV-_Nbg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>> -- 
>> Adam (ad...@csh.rit.edu)
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff76d73a-3baf-4053-b539-7734ba53e61d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to