Running Django tests from Python

26 views
Skip to first unread message

Shawn Milochik

unread,
Apr 21, 2011, 1:48:58 PM4/21/11
to django...@googlegroups.com
I want to use pyinotify[1] to monitor my project directory and run my
unit tests whenever I save a .py file.

The monitoring part is working. All I need now is to know how to call
the tests from my "watcher" script.

As noted in the docs[2], I'm already running setup_test_environment()
in my script.

Now, how do I do the equivalent of the following from within my Python script?
python manage.py test myapp1 myapp2

[1] https://github.com/seb-m/pyinotify
[2] http://docs.djangoproject.com/en/1.3/topics/testing/#running-tests-outside-the-test-runner

Thanks,
Shawn

Shawn Milochik

unread,
Apr 27, 2011, 12:38:15 PM4/27/11
to django...@googlegroups.com
I figure it's been long enough that I can bump this post.

I'm currently using subprocess to do this. There must be an easy way to simply invoke the tests from within Python.

So, how do you (within Python), do the equivalent of the following?:
    ./manage.py test myapp1, myapp2, myapp3

Thanks,
Shawn

Shawn Milochik

unread,
Apr 27, 2011, 12:41:00 PM4/27/11
to django...@googlegroups.com
Sorry, I realize that last post is missing the context of the original question.


Thanks,
Shawn

Kenny Meyer

unread,
Apr 27, 2011, 4:06:35 PM4/27/11
to django...@googlegroups.com
Hi Shawn,

http://docs.djangoproject.com/en/dev/ref/django-admin/#running-management-commands-from-your-code

Does this answer your question?

Kenny

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

Shawn Milochik

unread,
Apr 27, 2011, 4:47:55 PM4/27/11
to django...@googlegroups.com
On 04/27/2011 04:06 PM, Kenny Meyer wrote:
> Hi Shawn,
>
> http://docs.djangoproject.com/en/dev/ref/django-admin/#running-management-commands-from-your-code
>
> Does this answer your question?
>
> Kenny
>
Kenny,

This is *exactly* what I was looking for.

Unfortunately it doesn't work. It keeps saying that an app with that
label can not be found.

I've traced it down to django.db.models.loading.py, which imports
settings from django.conf, but it's
always 'django.conf.LazySettings object' instead of the proper settings
file.

This is odd, because os.environ['DJANGO_SETTINGS_MODULE'] is properly
set if I check it in pdb during that function.

I've even tried passing my settings module as a kwarg as described in
the doc you sent which doesn't work either.
In any case, I'm using the default -- 'settings.py' in the project folder.

Any ideas?

Thanks,
Shawn

Shawn Milochik

unread,
Apr 27, 2011, 4:56:49 PM4/27/11
to django...@googlegroups.com
On 04/27/2011 04:06 PM, Kenny Meyer wrote:

Never mind. More pdb action and I figured out that I had overwritten
DJANGO_SETTINGS_MODULE at the bash prompt I was using to try this. All
my fault. Yay.

Now it works, thanks.

Shawn


Reply all
Reply to author
Forward
0 new messages