Malcom many thanks for your reply I created a new project and app to with only one model and one test. It still fails I know I am missing something but I cant figure out what that is.
I tested this on both mac OSx10.5 and vista (both python 2.5.1 and django version 1.02) Here are my models.py and my tests.py http://dpaste.com/120843/ The only other thing I changed is add myproj.myapp to my INSTALLED_APPS On 15 feb, 03:31, Malcolm Tredinnick <malc...@pointy-stick.com> wrote: > On Sat, 2009-02-14 at 11:28 -0800, pault wrote: > > I have defined a custom error but if I test if custom error gets > > raised it fails if I test for Exception the test passes > > > class CustomError(Exception): > > """ > > This exception is my custom error > > """ > > > class Company(models.Model): > > name = models.CharField(max_length=200) > > > def test_error(self): > > raise CustomError('hello') > > > and in my tests.py: > > > import unittest > > from api.models import > > Company,Customer,Employee,Location,Product,ProductCategory,AllreadyPayedError,CustomError > > > #class AllreadyPayedException(Exception): pass > > You mean AlreadyPaidException. Trust me on this. :-) > > > > > > > class CompanyTestCase(unittest.TestCase): > > def setUp(self): > > self.company = Company.objects.create(name="lizto") > > > def test2(self): > > self.assertRaises(CustomError, self.company.test_error) > > > ====================================================================== > > ERROR: test2 (lizto.api.tests.CompanyTestCase) > > ---------------------------------------------------------------------- > > Traceback (most recent call last): > > File "/Users/......./tests.py", line 27, in test2 > > self.assertRaises(CustomError, self.company.test_error) > > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/ > > python2.5/unittest.py", line 320, in failUnlessRaises > > callableObj(*args, **kwargs) > > File "/Users/....../models.py", line 17, in test_error > > raise CustomError('hello') > > CustomError: hello > > Using the code you provide (after removing the imports that don't exist > in the code you provide), this works perfectly for me. So there's > something special about your setup. > > If I were you, I'd start from the simple example you show. Create an app > that only contains that models.py and that tests.py and fix the import > line to remove everything except Company and CustomError. That's what > passes for me. > > Regards, > Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---