Re: problem writing a unittest
On Fri, 2010-12-10 at 00:19 -0800, Daniel Roseman wrote: > The setup method should be spelled "setUp". Unittest is a descendant > of Java's jUnit and inherits its naming conventions, unfortunately. thanks - reminder to self: never type anything when it is possible to copy-paste -- regards Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: problem writing a unittest
On Dec 10, 6:53 am, Kenneth Gonsalves wrote: > hi, > > I am trying to write a unittest, but am getting an error. > > django version - trunk > model: > > class Nums(models.Model): > > num1 = models.IntegerField("First number") > num2 = models.IntegerField("Second number") > def addit(self): > return self.num1+self.num2 > > test: > > from django.utils import unittest > from addnums.models import Nums > > class TestNums(unittest.TestCase): > def setup(self): > """create a model and test if the result is correct""" > self.tnum = Nums.objects.create(num1=1,num2=2) > > def testaddit(self): > self.assertEqual(self.tnum.addit(),"3") > > and the error is: > > Traceback (most recent call last): > File "/home/lawgon/addition/../addition/addnums/tests.py", line 18, in > testaddit > self.assertEqual(self.tnum.addit(),"3") > AttributeError: 'TestNums' object has no attribute 'tnum' > > any clues? > -- > regards > Kenneth Gonsalves The setup method should be spelled "setUp". Unittest is a descendant of Java's jUnit and inherits its naming conventions, unfortunately. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
problem writing a unittest
hi, I am trying to write a unittest, but am getting an error. django version - trunk model: class Nums(models.Model): num1 = models.IntegerField("First number") num2 = models.IntegerField("Second number") def addit(self): return self.num1+self.num2 test: from django.utils import unittest from addnums.models import Nums class TestNums(unittest.TestCase): def setup(self): """create a model and test if the result is correct""" self.tnum = Nums.objects.create(num1=1,num2=2) def testaddit(self): self.assertEqual(self.tnum.addit(),"3") and the error is: Traceback (most recent call last): File "/home/lawgon/addition/../addition/addnums/tests.py", line 18, in testaddit self.assertEqual(self.tnum.addit(),"3") AttributeError: 'TestNums' object has no attribute 'tnum' any clues? -- regards Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.