Skip to main content

Code snippets which help writing automated tests for Django.

Project description

Wheel Status Latest Version License


Provide code snippets which help running tests in Django.


Install requirements:

pip install -r requirements.txt

Install Smarttest:

pip install django-smarttest

or current development version:

pip install hg+https:://




Preventing tests from touching database

import unittest

from smarttest.decorators import no_db_testcase

class SomeTestCase(unittest.TestCase):

     def test_some_test(self):

If you’ll accidentally write code that tries to run some query on database you’ll get exception.

Running only selected test types

import unittest

from smarttest.decorators import test_type

class SomeAcceptanceTestCase(unittest.TestCase):

     def test_some_acceptance_test(self):

class SomeUnitTestCase(unittest.TestCase):

     def test_some_unit_test(self):

class UnspecifiedTypeTestCase(unittest.TestCase):

     def test_some_test(self):
$ python -m unittest script
Ran 3 tests in 0.000s

$ IGNORE_TESTS=unit python -m unittest script
Ran 3 tests in 0.000s

OK (skipped=1)
$ IGNORE_TESTS=acceptance python -m unittest script
Ran 3 tests in 0.000s

OK (skipped=1)
$ IGNORE_TESTS=acceptance,unit python -m unittest script
Ran 3 tests in 0.000s

OK (skipped=2)

Test type can be any selected word. It doesn’t have to be “unit” or “acceptance”. You can have different test types for running in different environments if you need.

TestCase for use with switchable splinter driver

Simple TestCase that allows for simple switching between different drivers in tests.


TEST_DRIVER = 'firefox'  # or django or any other

In test:

from smarttest.testcases import SplinterTestCase

class SomeTestCase(SplinterTestCase):

     def test_some_test(self):
         self.browser.visit(self.get_host() + '/')

If you run tests continuously (e.g. doing Test Driven Development) TEST_DRIVER=’django’ (default setting) is the fastest driver that do not interrupt your workflow. However when you run your acceptance tests you may want to check how it behaves with real browser. Simply set TEST_DRIVER=’firefox’ or any other real browser supported by splinter.

Supported Django versions

Tested with:

  • Django 1.2.7 on python2.7
  • Django 1.3.7 on python2.7
  • Django 1.4.16 on python2.7
  • Django 1.5.11 on python2.7, python3.3, python3.4
  • Django 1.6.8 on python2.7, python3.3, python3.4
  • Django 1.7.1 on python2.7, python3.3, python3.4

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_smarttest-0.3.0-py2.py3-none-any.whl (12.5 kB) Copy SHA256 hash SHA256 Wheel py2.py3
django-smarttest-0.3.0.tar.gz (9.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page