Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 10, 2010 06:54:21

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 10, 2010 08:19:42

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

problem writing a unittest


On Dec 10, 6:53 am, Kenneth Gonsalves <law...@au-kbc.org> 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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 10, 2010 09:36:03

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 13th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support