3

I've been using a nose test runner for vim called qtpy and when my tests are simple unittest.TestCase all is well but the moment I need a database it's clear the nose test runner does not syncdb before it runs.

Does a test runner exist that will syncdb before each run? If not how are people getting around this issue when they run django tests that are more integration like?

if it matters, I am using a mocked settings file so my DJANGO_SETTINGS_MODULE is setup. In addition the sqlite db file is created and available to the test runner. But when nose runs the "django" test it fails to syncdb and results in something like this

 23     return Database.Cursor.execute(self, query, params)
 24 DatabaseError: no such table: foo_bar
 25 -------------------- >> begin captured logging << --------------------
 26 django.db.backends: DEBUG: (0.001) CREATE TABLE ROLLBACK_TEST (X INT); args=()
 27 django.db.backends: DEBUG: (0.000) INSERT INTO ROLLBACK_TEST (X) VALUES (8); ar...
 28 django.db.backends: DEBUG: (0.000) SELECT COUNT(X) FROM ROLLBACK_TEST; args=()
 29 django.db.backends: DEBUG: (0.001) DROP TABLE ROLLBACK_TEST; args=()
 30 django.db.backends: DEBUG: (0.000) INSERT INTO "foo_bar" ("first", "last" ...
 31 --------------------- >> end captured logging << -
Toran Billups
  • 27,715
  • 39
  • 150
  • 262

2 Answers2

1

are you using django's built in unittest?

from django.utils import unittest

The django unittest automatically will delete and syncdb before Every test is run

It seems like you might have some issues with the way you are running your test and having it recognize your django project and settings? If you use django's unittest you can seamlessly test your django project

dm03514
  • 50,477
  • 16
  • 96
  • 131
  • I'm using the builtin unittest as you mention but my test runner (qtpy) runs them using nosetest so django is not managing the setup/teardown of each test. I'm looking for a plugin that does work with django (vim plugin / python or ruby support is fine) -- OR -- some way to use this qtpy runner w/ django that works with manage.py – Toran Billups Mar 05 '13 at 18:13
1

I finally found a rock solid vim plugin written in python that works with django.

https://github.com/JarrodCTaylor/vim-python-test-runner

It only requires a single configuration file at the root of your project (no need to modify your vimrc over and over when you switch projects)

:e .vim-django

put each of your app names into a comma sep list, along with the settings you want them run with (ie- test / dev / ci / etc)

{"app_name": "website", "environment": "test"}

The above django app only has one installed app (website) and I want to run everything with test settings.

You also need to be using nose as your test runner so be sure you have this in your settings for test

INSTALLED_APPS += ('django_nose', )
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
Toran Billups
  • 27,715
  • 39
  • 150
  • 262