No :(

It's still a mystery. It's really annoying. It resurfaced again about 2 
weeks ago and it caused several test failures that I could never reproduce 
locally. 
I have some tests that look like this:

class TestCase(DjangoTestCase):
  def setUp(self):
      super(TestCase, self).setUp()
      User.objects.create(...)
      assert self.client.login(...)

  def test_something(self):
      response = self.client.get('/some/url/for/signed/in/people')
      assert response.status_code == 200
   
But sometimes, for no reason I can understand, that fails because at the 
point of doing the self.client.get the self.client.session is empty! :(



On Friday, June 5, 2015 at 8:10:52 AM UTC-7, mlpi...@qdqmedia.com wrote:
>
> Hi, I am facing a similar issue and have not found any solution yet. I was 
> wondering if you had been able to fix this?
>
> On Tuesday, 31 March 2015 22:27:32 UTC+2, Peter Bengtsson wrote:
>>
>> I have this code that looks something like this (django 1.6.11):
>>
>> def test_something(self):
>>     url = someobject.get_url()
>>     User.objects.create_user('a', 'a...@example.com', 'secret')
>>     assert self.client.login(username='a', password='secret')
>>     r = self.client.get(url)
>>     assert r.status_code == 302  # because you're not allowed to view it
>>     someobject.privacy_setting = 'different'
>>     r = self.client.get(url)
>>     assert r.status_code == 200  # now you can view it according the 
>> business logic
>>
>>
>> This code has been working for many many months but suddenly it started 
>> to Heisenfail with the last line being 302 != 200.
>> It might be related to caching somewhere else because it ONLY ever fails 
>> (if it fails!) when I run the whole test suite. 
>> After a lot of painful debugging I concluded that sometimes, that last 
>> self.client.get(url) causes `request.user == <SimpleLazyObject: 
>> <django.contrib.auth.models.AnonymousUser object at 0x112318f50>>`
>>
>> I.e. for the second request made by that logged in client, it's all of a 
>> sudden NOT logged in!! Not always. Only sometimes. :(
>>
>> I put in a debugging line just before that last test like `assert 
>> self.client.session['_auth_user_id']` and that sometimes fails. Almost as 
>> if the testclient loses its session store DURING the lifetime of the test. 
>> Sometimes. 
>>
>>
>> Anybody seen anything similar that might be able to explain it or give me 
>> a clue?
>>
>>
>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a0207a9f-2928-48a5-80f5-969e2180675e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to