Why if I run python manage.py test appname in my terminal is: Ran 0 tests in 0.000s OK
This is my tests.py:
from django.test import TestCase
import appname.factories
class UserProfileTest(TestCase):
def sample_data(self):
for i in range(0, 10):
user = appname.factories.UserProfileFactory.create()
My models.py:
from django.db import models
class UserProfile(models.Model):
street = models.CharField(max_length=250)
tel = models.CharField(max_length=64, default='', blank=True)
postcode = models.CharField(max_length=250)
def __unicode__(self):
return self.tel
My factories.py (factory boy):
from appname.models import *
import factory
class UserProfileFactory(factory.Factory):
FACTORY_FOR = UserProfile
street = factory.Sequence(lambda n: 'Street' + n)
tel = factory.Sequence(lambda n: 'Tel' + n)
password = 'abcdef'
Your individual test functions should begin with the word ‘test’.
You need to change the function
def sample_data(self):todef test_sample_data(self):The test runner will look for any classes in a file called
tests.py, which sit in the root of your app, and which extendunittest.TestCase. Then it will run any functions within that class which begin with the word test (plus one or two other functions such assetup())I’m probably being obtuse, but I couldn’t see anything in the main django testing docs stating that functions must begin with the word test. Anyway, there’s a reference to the requirement in this (official) tutorial.