Django test runner not finding tests


I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from, is in the same folder as and your test class subclasses TestCase, it should all get picked up automatically. This isn't working for me, when I run test <myapp> it doesn't find any tests.

I started with all my tests in their own package but have simplified it down to all tests just being in my file. The current looks like:

import unittest
from pyDietTracker.models import Weight
from pyDietTracker.weight.DisplayDataAdapters import DisplayWeight

class TestDisplayWeight(unittest.TestCase):

    def setUp(self):

    def tearDown(self):

    def testGetWeightInStone_KG_Correctly_Converted(self):
        weight = Weight()
        weight.weight = 99.8

        testAdapter = DisplayWeight(weight)
        self.assertEquals(testAdapter.GetWeightInStone(), '15 st 10 lb')   

I have tried it by subclassing the Django TestCase class as well but this didn't work either. I'm using Django 1.1.1, Python 2.6 and I'm running Snow Leopard.

I'm sure I am missing something very basic and obvious but I just can't work out what. Any ideas?

Edit: Just a quick update after a comment


To get the tests to run I am running test pyDietTracker

8/5/2015 1:55:55 PM

Accepted Answer

Worked it out.

It turns out I had done startproject pyDietTracker but not python startapp myApp. After going back and doing this, it did work as documented. It would appear I have a lot to learn about reading and the difference between a site and an app in Django.

Thank you for your help S.Lott and Emil Stenström. I wish I could accept both your answers because they are both helped alot.

Most important lesson Tests only work at the app level not the site level

1/11/2010 12:10:50 AM

I had the same issue but my problem was different.

I was getting Ran 0 tests, as OP.

But it turns out the test methods inside your test class must start with keyword test to run.


from django.test import TestCase

class FooTest(TestCase):
    def setUp(self):

    def tearDown(self):

    def this_wont_run(self):
        print 'Fail'

    def test_this_will(self):
        print 'Win'

Also the files with your tests have to start with test keyword.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow