user441495 user441495 - 1 year ago 60
Python Question

Why does django not see my tests?

I've created module, filled with

from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User
from django.contrib.sites.models import Site

from forum.models import *

class SimpleTest(TestCase):

def setUp(self):
u = User.objects.create_user("ak", "", "pwd")
Site.objects.create(domain="", name="")

def content_test(self, url, values):
"""Get content of url and test that each of items in `values` list is present."""
r = self.c.get(url)
self.assertEquals(r.status_code, 200)
for v in values:
self.assertTrue(v in r.content)

def test(self):
self.c = Client()
self.c.login(username="ak", password="pwd")

self.content_test("/forum/", ['<a href="/forum/forum/1/">forum</a>'])

and placed it in folder with my application.
When i run tests by

python test forum

after creating the test database i get an answer "Ran 0 tests in 0.000s"

What am i doing wrong ?

Here is my project hierarchy:

forum (it's my app):

I renamed to Eclipse got that this module is with tests, but answer is still "Ran 0 tests in 0.000s"

Answer Source

There is something not quite right if you are getting the same result after renaming the file to How are you running the tests? Are you doing so from the command line or have you set up a custom run target using Eclipse? Please try it from the command line if you haven't already.

Also fire up Django shell (python shell) and import your tests module.

from import SimpleTest

Does the import work correctly?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download