On Thu, Apr 15, 2010 at 3:32 PM, Dan <[email protected]> wrote: > Hi, > I'm pretty new to Django, and I'm trying to create a few simple tests > for my project. I've created a very basic fixture and I'm trying to > just load it and see that the data is there. Nothing big. I've read > the documentation here: > http://docs.djangoproject.com/en/dev/topics/testing/ > but I must be missing something because I can't get it to work. This > is how I have my app set up: > articles/ > models.py > tests.py > fixtures/ > articles-test.json > > tests.py looks like this: > ... > class ArticleTests(unittest.TestCase): > fixtures = ['articles/fixtures/articles-test.json'] >
Remove the 'articles/fixtures/' part. Notice there are no paths in the the example doc -- fixtures directories under each app listed in INSTALLED_APPS are automatically searched for fixtures. > def test_article_exists(self): > a = Article.objects.get(pk=1) > self.assertEquals(headline='foo') > > When I run manage.py test articles, it's finding my test and running, > but it fails with > ... > DoesNotExist: Article matching query does not exist. > > One thing that is confusing me is that although the debug messages say > the test db tables are being created, etc, it says nothing about > whether it's loading my fixture, or whether it's trying and failing. > The documentation is unclear about exactly where the fixtures need to > be located, so I've tried putting them in a lot different places, with > no luck. I tried mangling the json file, so if it found it it should > throw a parse error, and still there was no difference, so I think the > problem must be that it's not loading the fixture, but I just can't > figure out how to point it in the right directions. > You are right, there is no diagnostic message issued when a fixture named in fixtures isn't found. There may be a ticket open on that. As for where the file needs to be...the test doc you point to does say "Once you've created a fixture and placed it in a fixtures directory in one of your INSTALLED_APPS, you can use it in your unit tests..." -- does that not make it clear where the file needs to go? Karen -- You received this message because you are subscribed to the Google Groups "Django users" 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-users?hl=en.

