Django Nose Lint Quickstart - Enforce fast unit tests
In the battle for blazing fast unit tests, you need all the tools you can get at your disposal. Enter django-nose-lint, a new Nose plugin that lets you enforce certain runtime constraints on your test suite. You can just flat out fail tests that take over a configurable amount of time. You can also get more granular and fail tests that try to do certain slow stuff. For example, using the Django test client.
Here are the things it can currently check for:
ESOK = Used a TCP socket
ECLI = Used the Django Test Client
ETEM = Tried to render a Django template
ESLO = Test took over 1 second (takes –maxms argument)
EALL = All of the above
Quickstart for exsting Django projects already using django-nose
If you’re already running django-nose on your Django app, all you need to do is install django-nose-lint, and run your tests with the --lint flag.
Starting from scratch on a new Django project
This is mostly an re-hash of the django-nose setup docs. I assume you have virtualenv installed, and want to use it to isolate this skunkworks from your existing python stuff.
First, setup a new Django project inside virtualenv.
Then, edit your Django settings.py file to do basic setup, and attach django-nose.
Create a basic test that we want to fail. Create this as mysite/tests.py. It should be along-side urls.py in the directory structure.
Run your test suite.
If you run without the --lint flag, the same test should pass.
Call for ideas
I’m looking for some more ideas of things to fail in unit tests. Please submit a bug to the tracker if you have any ideas.