Splitting tests.py to package

Skip to first unread message

Jari Pennanen

Nov 5, 2010, 4:57:43 PM11/5/10
to Django users
I've been trying to split tests.py, but I've noticed that models
defined inside test module does not work. Normally one can define
models in tests.py like this:

class JSONFieldModel(models.Model):
json = JSONField()

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

def test_json_serialization(self):
"""JSONField serialization"""
thedata = {'test': 5}

jsdb = JSONFieldModel(json=thedata)
del jsdb

jsdb = JSONFieldModel.objects.get(pk=1)
self.failUnlessEqual(thedata, jsdb.json,
'JSON Serialization mismatch')

And they are created to test database just fine. But when I split the
tests.py to package and have tests/__init__.py import all, it throws
me error of not having database tables. Tests do start just fine, but
these models are not apparently created.

Is there any good workaround for this? I really like the idea of
splitting long tests.py to logical modules.
Reply all
Reply to author
0 new messages