#7694: Models that are imported into tests.py (and utilize signals) result in
parallel tests that break test cases
------------------------------+---------------------------------------------
 Reporter:  davenaff          |       Owner:  nobody    
   Status:  new               |   Milestone:            
Component:  Unit test system  |     Version:  SVN       
 Keywords:                    |       Stage:  Unreviewed
Has_patch:  0                 |  
------------------------------+---------------------------------------------
 In a sample models.py file:

 {{{
 def MyModel(models.Model):
     """
     >>> u=User.objects.create_user('test2','[EMAIL PROTECTED]')
     >>> u.email='new'
     >>> u.save()
     """
     anyfield = models.BooleanField()

 COUNT = 0

 def user_pre_save(sender, instance, signal, *args, **kwargs):
     global COUNT
     r = random.randint(1,50)
     print 'pre_save: count: %s random: %s' %(COUNT, r)
     COUNT +=1

 dispatcher.connect(user_pre_save, signal=signals.pre_save,
 sender=User)
 }}}

 Then create a tests.py and add this import (that's all you need):
 {{{
 from myproject.models import MyModel
 }}}

 Here is what the test output looks like.  Note that it looks like we're
 creating two duplicate threads each with their own state (COUNT doesn't
 increment between the runs of user_pre_save, but random is different.


 {{{
 pre_save: count: 0 random: 49
 pre_save: count: 0 random: 23
 ...
 Failed example:
     u=User.objects.create_user('test2','[EMAIL PROTECTED]')
 Expected nothing
 Got:
     pre_save: count: 1 random: 13
     pre_save: count: 1 random: 2
 ...

 Failed example:
     u.save()
 Expected nothing
 Got:
     pre_save: count: 2 random: 18
     pre_save: count: 2 random: 49
 }}}


 I've not been able to figure out what is causing this.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/7694>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to