Kristian Glass - Do I Smell Burning?

The Most Efficient Django Test

Everyone loves superlatives, especially when I’m the one who gets to choose the efficiency metric so they’re probably not even hyperbole…!

It’s six lines long, and exercises your settings, your URL config, and potentially even much more!

from django.test import TestCase


class BasicTestCase(TestCase):
    def test_getting_root(self):
        self.client.get('/')

There are better quality tests. There are more thorough tests. That’s not what this is about.

(Faithful readers may note that in my previous post about my Django template I claimed it was a 5 line test. Alas I had insufficient empty lines before the class declaration, and a very weird bug going on where flake8 appears to erroneously validate improperly-formatted Python - any help would be very much appreciated please!)

Comments