2

With the current stable django_nose (0.1.3) the models aren't even properly found and loaded, I get the following exception when running the tests:

django.db.utils.DatabaseError: (1146, "Table 'test_appdatabase.django_site' doesn't exist")

using the git version of django_nose I managed to get my models to be created into the test database properly, however they are all empty, with Django's testrunner I get some basic data loaded into the tables, such as the django_site and auth_permission tables:

django_site
id      domain  name
1       example.com     example.com

When I run the test suite with django_nose installed and setup, I get the following exception:

DoesNotExist: Site matching query does not exist.

Any Ideas?


Update: running with -v 2, it seems it is running the post-sync handlers (syncdb) for the applications

Running post-sync handlers for application sites
Creating example.com Site object
Adding content type 'sites | site'
Adding permission 'sites | site | Can add site'
Adding permission 'sites | site | Can change site'
Adding permission 'sites | site | Can delete site'

So it seems to be adding them, yet somewhere they are being deleted.


Further Update:

Looking at the MySQL Query log, the sequence of events is

  1. Do a syncdb on the test database
  2. Truncate every single table (why?, this is where my issue is)
  3. Run the tests

An example truncation from the query log:

TRUNCATE `django_site`

Why are the tables being truncated? Is it so that the tests don't pollute each other, is there a way to disable that?


I believe this to be the final update:

using the standard django runner, the same thing happens,

  1. tables are created
  2. post-sync inserts data
  3. the tables are truncated
  4. Alter table called to set AUTO_INCREMENT = 1

Except for the next step:

  1. Data is inserted back in

    INSERT INTO django_site (domain, name) VALUES ('example.com', 'example.com')

Not sure why this is happening here but not with django_nose

Pykler
  • 14,565
  • 9
  • 41
  • 50

2 Answers2

1
  1. Is the sites app in your INSTALLED_APPS? The nose test runner extends django's test runner, which should be calling syncdb and picking up all your installed apps.
  2. What does your test case look like? django-nose is not responsible for loading your fixtures (neither is the normal Django test runner). Fixtures get loaded by django.test.TestCase.

Edit: All the things you're describing happen in _fixture_setup() from Django's TestCase. The truncate and such happens in flush and then the fixtures get set up.

https://github.com/django/django/blob/master/django/test/testcases.py#L258

jbalogh
  • 11
  • 2
  • Yeah you are right, but it is not the fixtures, as you mentioned the syncdb is being called, but then the tables are being truncated, see my latest update above. – Pykler Aug 03 '11 at 16:36
  • Is the flush command handled differently by django_nose? seems that the django flush emits the post sync signal – Pykler Aug 03 '11 at 17:08
  • Diff displayed in https://github.com/jbalogh/django-nose/issues/39 fixes my issue – Pykler Aug 04 '11 at 22:23
0

The diff displayed in https://github.com/jbalogh/django-nose/issues/39 fixes this issue.

Pykler
  • 14,565
  • 9
  • 41
  • 50