Re: How do I run test and get results programmatically? (django, south, fixtures, sqlite)

2011-03-14 Thread Jumpfroggy
@gladys,

While that didn't solve my original question, it did solve another
related problem.  Before, I had issue with migrations failing since
they depended on pre-existing data (which did not exist in the blank
testing database).  But if I added an initial_data.json fixture, it
gets run for every migration - during prod and testing.  This is bad.

So I went with "SOUTH_TESTS_MIGRATE = False", then I manually load the
"test_data" fixture during the first test.  Works great.

I still can't figure out why running "python manage.py test" and
running the above code have such different results.  I'd love to
figure out why, since it would be easier to use the API calls and look
in the "failures" var than it is to run the "python manage.py test"
command and parse through the output.  But for now, the latter gets
things working.

So thanks!  My original question is still open, but I'm un-stuck and
can continue working for now.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How do I run test and get results programmatically? (django, south, fixtures, sqlite)

2011-03-13 Thread gladys
I'm not sure if this is what you need, but if the problem is with the
migrations not being run, you can specify a setting in your
settings.py to use syncdb when running tests.

#settings.py
SOUTH_TESTS_MIGRATE = False # make test database created using syncdb
rather than migrations

Goodluck.

--
Gladys
http://bixly.com


On Mar 12, 5:32 am, Jumpfroggy  wrote:
> I have an app that I'm starting to write tests for.  The app uses
> south for all migrations and mysql for the db.
>
> I wrote some tests and also created an initial_data.json fixture to
> provide some default data.  If I run "python manage.py test", the
> database is created via sqlite, the tests are run, and then the report
> is spit out.  This works fine.
>
> However, I want to automate this where I can programmatically run
> tests, find the failures, and do some custom logging/saving of the
> failures.  How do I run the tests in python?
>
> I've tried a few variations of the below code, but the problem is the
> database.  When I run the "python manage.py test" command, it
> automatically uses sqlite3 as the backend, creates the database, and
> uses it for all tests.  However, when I run my own tests, it uses the
> mysql backend.  If I force it to use sqlite, is has problems with the
> fixtures because the migrations are not run before installing the
> fixtures.
>
> How do I run tests manually using the same database setup that happens
> when using the manage.py test command?
>
> My code:
>
>     import my_application.settings
>
>     # NOTE: Use this to force the testing database to use the sqlite
> engine.
>     my_application.settings.DATABASE_ENGINE = 'sqlite3'
>
>     from django.core.management import setup_environ
>     setup_environ(my_application.settings)
>
>     from django.conf import settings
>     from django.test.utils import get_runner
>
>     verbosity = 1
>     interactive = False
>     failfast = True
>     TestRunner = get_runner(settings)
>
>     test_labels = ()
>
>     test_runner = TestRunner(verbosity=verbosity,
> interactive=interactive, failfast=failfast)
>     failures = test_runner.run_tests(test_labels)
>
> And this is the error I get:
>
>     calling TestRunner.run_tests()
>       verbosity: 1
>       interactive: False
>       failfast: True
>       test_labels: ()
>     connection.settings_dict: {'ENGINE': 'django.db.backends.sqlite3',
> 'TEST_MIRROR': None, 'NAME': 'my_application', 'TEST_CHARSET': None,
> 'TIME_ZONE': 'America/New_York', 'TEST_COLLATION': None, 'OPTIONS':
> {}, 'HOST': '', 'USER': 'my_application', 'TEST_NAME': None,
> 'PASSWORD': 'my_application', 'PORT': ''}
>     test_databases: {('', '', 'django.db.backends.sqlite3',
> 'my_application'): ['default']}
>     Creating test database 'default'...
>     Syncing...
>     Creating table django_admin_log
>     Creating table auth_permission
>     Creating table auth_group_permissions
>     Creating table auth_group
>     Creating table auth_user_user_permissions
>     Creating table auth_user_groups
>     Creating table auth_user
>     Creating table auth_message
>     Creating table django_content_type
>     Creating table django_session
>     Creating table django_site
>     Creating table south_migrationhistory
>     Installing index for admin.LogEntry model
>     Installing index for auth.Permission model
>     Installing index for auth.Group_permissions model
>     Installing index for auth.User_user_permissions model
>     Installing index for auth.User_groups model
>     Installing index for auth.Message model
>     No fixtures found.
>
>     Synced:
>      > django.contrib.admin
>      > django.contrib.auth
>      > django.contrib.contenttypes
>      > django.contrib.sessions
>      > django.contrib.sites
>      > south
>
>     Not synced (use migrations):
>      - my_application
>     (use ./manage.py migrate to migrate these)
>     test_db_name: ':memory:'
>     Problem installing fixture 'C:\virtualenv-my_application\lib
> \site-packages\django\contrib\auth\fixtures\authtestdata.json':
> Traceback (most recent call last):
>       File "C:\virtualenv-my_application\lib\site-packages\django\core
> \management\commands\loaddata.py", line 174, in handle
>         obj.save(using=using)
>       File "C:\virtualenv-my_application\Lib\site-packages\django\core
> \serializers\base.py", line 165, in save
>         models.Model.save_base(self.object, using=using, raw=True)
>       File "C:\virtualenv-my_application\Lib\site-packages\django\db
> \models\base.py", line 566, in save_base
>         created=(not record_exists), raw=raw)
>       File "C:\virtualenv-my_application\Lib\site-packages\django
> \dispatch\dispatcher.py", line 172, in send
>         response = receiver(signal=self, sender=sender, **named)
>       File "C:\my_application\..\my_application\models.py", line 1175,
> in _create_profile_for_user
>         profile.save()
>       File "C:\virtualenv-my_application\Lib\site-packages\django\db
> 

How do I run test and get results programmatically? (django, south, fixtures, sqlite)

2011-03-11 Thread Jumpfroggy
I have an app that I'm starting to write tests for.  The app uses
south for all migrations and mysql for the db.

I wrote some tests and also created an initial_data.json fixture to
provide some default data.  If I run "python manage.py test", the
database is created via sqlite, the tests are run, and then the report
is spit out.  This works fine.

However, I want to automate this where I can programmatically run
tests, find the failures, and do some custom logging/saving of the
failures.  How do I run the tests in python?

I've tried a few variations of the below code, but the problem is the
database.  When I run the "python manage.py test" command, it
automatically uses sqlite3 as the backend, creates the database, and
uses it for all tests.  However, when I run my own tests, it uses the
mysql backend.  If I force it to use sqlite, is has problems with the
fixtures because the migrations are not run before installing the
fixtures.

How do I run tests manually using the same database setup that happens
when using the manage.py test command?

My code:

import my_application.settings

# NOTE: Use this to force the testing database to use the sqlite
engine.
my_application.settings.DATABASE_ENGINE = 'sqlite3'

from django.core.management import setup_environ
setup_environ(my_application.settings)

from django.conf import settings
from django.test.utils import get_runner

verbosity = 1
interactive = False
failfast = True
TestRunner = get_runner(settings)

test_labels = ()

test_runner = TestRunner(verbosity=verbosity,
interactive=interactive, failfast=failfast)
failures = test_runner.run_tests(test_labels)

And this is the error I get:

calling TestRunner.run_tests()
  verbosity: 1
  interactive: False
  failfast: True
  test_labels: ()
connection.settings_dict: {'ENGINE': 'django.db.backends.sqlite3',
'TEST_MIRROR': None, 'NAME': 'my_application', 'TEST_CHARSET': None,
'TIME_ZONE': 'America/New_York', 'TEST_COLLATION': None, 'OPTIONS':
{}, 'HOST': '', 'USER': 'my_application', 'TEST_NAME': None,
'PASSWORD': 'my_application', 'PORT': ''}
test_databases: {('', '', 'django.db.backends.sqlite3',
'my_application'): ['default']}
Creating test database 'default'...
Syncing...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table south_migrationhistory
Installing index for admin.LogEntry model
Installing index for auth.Permission model
Installing index for auth.Group_permissions model
Installing index for auth.User_user_permissions model
Installing index for auth.User_groups model
Installing index for auth.Message model
No fixtures found.

Synced:
 > django.contrib.admin
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > south

Not synced (use migrations):
 - my_application
(use ./manage.py migrate to migrate these)
test_db_name: ':memory:'
Problem installing fixture 'C:\virtualenv-my_application\lib
\site-packages\django\contrib\auth\fixtures\authtestdata.json':
Traceback (most recent call last):
  File "C:\virtualenv-my_application\lib\site-packages\django\core
\management\commands\loaddata.py", line 174, in handle
obj.save(using=using)
  File "C:\virtualenv-my_application\Lib\site-packages\django\core
\serializers\base.py", line 165, in save
models.Model.save_base(self.object, using=using, raw=True)
  File "C:\virtualenv-my_application\Lib\site-packages\django\db
\models\base.py", line 566, in save_base
created=(not record_exists), raw=raw)
  File "C:\virtualenv-my_application\Lib\site-packages\django
\dispatch\dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
  File "C:\my_application\..\my_application\models.py", line 1175,
in _create_profile_for_user
profile.save()
  File "C:\virtualenv-my_application\Lib\site-packages\django\db
\models\base.py", line 456, in save
self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
  File "C:\virtualenv-my_application\Lib\site-packages\django\db
\models\base.py", line 549, in save_base
result = manager._insert(values, return_id=update_pk,
using=using)
  File "C:\virtualenv-my_application\Lib\site-packages\django\db
\models\manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
  File "C:\virtualenv-my_application\Lib\site-packages\django\db
\models\query.py", line 1518, in insert_query
return