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

  • SEARCH
  • Home
  • 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 5843281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:07:58+00:00 2026-05-22T12:07:58+00:00

I have finally decided to create unit test for all my code. That is

  • 0

I have finally decided to create unit test for all my code. That is I’m trying to create fixtures based on my models to test my function against them.

I have create a json fixture using dumpdata command and placed it under fixtures directory on my app. The following is the code on my test:

import unittest
from mysite.myapp.models import Post

class RatingTestCase(unittest.TestCase):
  fixtures = [
      'posts.json',
  ]

def test_me(self):
  p = Post.objects.all()
  self.assertTrue(p)

I run my test using the following command on my Arch Linux machine:

python2.7 manage.py test myapp

It creates a sqlite database and installs all the tables and indeces, however at the end it says no fixtures found and it says my test failed since it didn’t find any data.

I’m running the latest revision of development version of Django and noticed that based on the documentation I am supposed to import unittest using:

from django.utils import unittest

However, when I do this, it complains that unittest cannot be imported. That’s why I import
unittest directly from my python path which worked.

I’ve tried to mock django model objects before, but I think it’s better to test Django apps using fixtures than using mock libraries. Any idea how to load the fixtures?

Thanks in advance.

EDIT: If I change my fixture name to initial_data.json, it will load it every time I run my test. However, I still need to have multiple fixture names for running different tests.

EDIT: I got it working by importing TestCase from the following:

from django.test import TestCase
  • 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-05-22T12:07:59+00:00Added an answer on May 22, 2026 at 12:07 pm

    There are a couple things that could help:

    1. You can run the test with –verbosity=2 to see which directories django looks in for fixtures.
    2. django TestCase is what django recommends to use, opposed to unittest.
    3. Where is your fixture directory/file located? If it’s not in your app you have to specify a fixture directory in your settings file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently decided that I just have to finally learn C/C++, and there is
I have finally decided to go with the Entity Framework since it has the
I have seen this for a long time, and finally decided to put the
I have finally started messing around with creating some apps that work with RESTful
I have some old C# plugin code that was implemented strictly with Reflection. In
I have done my fair amount of research and finally decided to ask this.
After long search with no luck, finally I have decided to ask here. I
Well, I've finally decided that I'm not crazy. So, that leaves DataMapper. Here's what
After years of using the big ugly MFC ASSERT macro, I have finally decided
I have been struggling with this thing for a while so I finally decided

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.