← Dynamic State Machines | The Scourge of Slow Tests (and What to Do About It) →

Released django-hotrunner

Just a quick note to say that my company, MetaMetrics just released django-hotrunner on BitBucket. django-hotrunner was written to scratch our development team's own itches around running django tests. It's a small module which provides a drop-in replacement for Django's test runner which adds some new functionality. First, it bypasses unwanted apps when running the test suite, including the django.contrib apps by default, and any others specified by the user. Second, it provides running times for individual tests when run in verbose mode.

In order to activate django-hotrunner, all you do is add the following to the settings file in your django project:

TEST_RUNNER = 'hotrunner.HotRunner'

To see how long individual tests take, just run the test suite with verbosity of 2 or greater.

$ python manage.py test --verbosity=2
test_absolute_url (news.tests.NewsModelAbsoluteURLTestCase) ... (1.103603s) ok
test_empty_body_returns_empty_html (news.tests.NewsModelMarkdownTestCase) ... (0.000215s) ok
test_markdown_saved_to_html (news.tests.NewsModelMarkdownTestCase) ... (0.014008s) ok
test_unicode_markdown_converted_appropriately (news.tests.NewsModelMarkdownTestCase) ... (0.000803s) ok
test_unicode_strings_must_be_decoded (news.tests.NewsModelMarkdownTestCase) ... (0.000683s) ok
test_basic_slug_creation (news.tests.NewsModelSlugificationTestCase) ... (0.001656s) ok
test_existing_slugs_do_not_get_overridden (news.tests.NewsModelSlugificationTestCase) ... (0.000307s) ok
test_slugifying_disambiguates_slugs (news.tests.NewsModelSlugificationTestCase) ... ERROR

We've found this very useful for general profiling of our tests. Fast tests make for more fun development. They also help guide our intuition as to what parts of our projects might be slow in production as well (though should by no means be taken as definitive in that regard).

To skip tests from apps beside the django.contrib apps, specify them in your settings module.

EXCLUDED_TEST_APPS = ['south', 'djcelery']

The tests from South and Celery will now be ignored when you run your test suite. If you want to add them back in, set TEST_ALL_APPS = True.

You can check out the code from bitbucket or pip install it directly from the repo:

$ pip install -e hg+http://bitbucket.org/metametrics/django-hotrunner#egg=django-hotrunner

We should have it up on PyPI soon. Please try it out and post issues or feature requests on the BitBucket issue tracker.

Comments !