Forms test run on development database instead of test database

33 views
Skip to first unread message

Merouane Atig

unread,
Jan 26, 2015, 7:07:54 AM1/26/15
to django...@googlegroups.com
Hi,

I have a strange issue with a forms test and I would like to know if I'm doing something wrong or if it is a Django bug.

I created a repo to reproduce the issue I have: https://github.com/merwan/django-choicefield

I have a DomainForm class with a choice field populated from a table in the database. I'm trying to test it using the Django testing tools, but I get the error "django.db.utils.OperationalError: no such table: myapp_topleveldomain" (see the README in the Github repo for the full stack trace).

If I first create my development database and migrate it, then I do not have any error. I expected that the test would run on the test database but it is not the case.

My test environment should work properly as I also created a model test which runs correctly on the test database and do not need the development database.

Can you tell me what would be the proper way to write this test so that it runs on the test database? Is it a bug with the Django testing tools or am I doing something wrong when populating my ChoiceField?

I'm using Django 1.7.3 and Python 3.4.0

Thanks for your help

Collin Anderson

unread,
Jan 27, 2015, 3:58:56 PM1/27/15
to django...@googlegroups.com
Hi,

I just tried out your project. Looking at the stacktrace, the test module is importing forms (before the test starts). The forms module is running a query on startup for choices.

Don't do queries on startup. :)

Collin

Merouane Atig

unread,
Jan 29, 2015, 3:48:48 AM1/29/15
to django...@googlegroups.com
Thank you for the explanation. So I suppose a better way to do it whould be to provide initialize the choices in the DomainForm __init__?
Reply all
Reply to author
Forward
0 new messages