Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:05:35+00:00 2026-06-08T12:05:35+00:00

I wrote a unit test checking whether initial data is loaded correctly. However the

  • 0

I wrote a unit test checking whether initial data is loaded correctly. However the Node.objects.all().count() always returns 0, thus it seems as the fixtures are not loaded at all. There is no output/error msg in the command line that fixtures are not loaded.

from core.models import Node

class NodeTableTestCase(unittest.TestCase):
    fixtures = ['core/core_fixture.json']
    def setUp(self):
        print "nothing to prepare..."

    def testFixture(self):
        """Check if initial data can be loaded correctly"""
        self.assertEqual(Node.objects.all().count(), 14) 

the fixture core_fixture.json contains 14 nodes and I’m using this fixture as a initial data load into the db using the following command:

python manage.py loaddata core/core_fixture.json

They are located in the folder I provided in the settings.py setting FIXTURE_DIRS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:05:38+00:00Added an answer on June 8, 2026 at 12:05 pm

    Found the solution in another thread, answer from John Mee

    # Import the TestCase from django.test:
    
    # Bad:  import unittest
    # Bad:  import django.utils.unittest
    # Good: import django.test
    
    from django.test import TestCase
    
    class test_something(TestCase):
        fixtures = ['one.json', 'two.json']
        ...
    

    Doing this I got a proper error message, saying that foreign key is violated and I had to also include the fixtures for the app “auth”. I exported the needed data with this command:

    manage.py dumpdata auth.User auth.Group > usersandgroups.json
    

    Using Unittest I got only the message that loading of fixture data failed, which was not very helpful.

    Finally my working test looks like this:

    from django.test import TestCase
    
    class NodeTableTestCase2(TestCase):
        fixtures = ['auth/auth_usersandgroups_fixture.json','core/core_fixture.json']
    
        def setUp(self):
            # Test definitions as before.
            print "welcome in setup: while..nothing to setup.."
    
        def testFixture2(self):
            """Check if initial data can be loaded correctly"""
            self.assertEqual(Node.objects.all().count(), 11)  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a unit test that will loop through all action methods
I wrote unit test (JUnit 4) that performs some logic and writes result to
I have a method calling localtime that I wrote a unit test for. I
How would one test whether data structure built properly? I'm implementing kind of modified
I have a unit test to check whether a method returns the correct IEnumerable
I wrote an unit-test using MSTest for my Application which uses functionality from a
I wrote an unit-test for an activity which finally puts a message into a
I wrote a unit test for my code. The code looks like the following:
How do I unit-test a Zend_Form form class I wrote for my application? I
I am trying to unit test an action filter I wrote. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.