mi sono imbattuto in questo, e elaborato la seguente soluzione:
Nel vostro frontend/tests.py, impostare le cose in questo modo:
# get the straight-up Python unittest without the Django machinery
# NOTE: this is unittest2, a backport of unit testing features from Python 2.7
# (running 2.6 at the time of writing)
from django.utils import unittest
# get the Django wraps
from django.test import TestCase as DjangoTestCase
# [..]
# your normal Django unit tests, inheriting from DjangoTestCase
# [..]
class MyTest(unittest.TestCase):
def runTest(self): # NOTE: required name
self.failUnless(True is True)
def runNonDjangoTests():
return MyTest() # or unittest.TestSuite([ MyTest(), .. ])
si esegue questo test con
~$ unit2 myapp.tests.runNonDjangoTests
Per ulteriori informazioni, vedere http://pypi.python.org/pypi/unittest2
Ciò consente anche di eseguire test unitari sul database principale, con tutti gli effetti collaterali potenzialmente distruttivi. Nota che unit2 è piuttosto pericoloso in questo contesto, se chiami unit2 myapp.tests eseguirà tutti i tuoi normali test di Django senza metterli in un database di test.
Certo, ma questo crea un nuovo database di test da eseguire contro. Come posso eseguirlo sul database principale (non test)? – Leopd