Skip to main content
Wheel Status Latest Version License

Goal

Provide code snippets which help running tests in Django.

Installation

Install requirements:

pip install -r requirements.txt

Install Smarttest:

pip install django-smarttest

or current development version:

pip install hg+https:://bitbucket.org/kidosoft/django-smarttest

Configuration

INSTALLED_APPS =  [
 ...
 'smarttest',
 ...
]

Usage

Preventing tests from touching database

import unittest

from smarttest.decorators import no_db_testcase

@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

@test_type('acceptance')
class SomeAcceptanceTestCase(unittest.TestCase):

     def test_some_acceptance_test(self):
         ...

@test_type('unit')
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

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

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

OK (skipped=1)
$ IGNORE_TESTS=acceptance,unit python -m unittest script
ss.
----------------------------------------------------------------------
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.

In settings.py:

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

Documentation

http://kidosoft.pl/docs/django-smarttest/

Release files for django-smarttest 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-smarttest 0.3.0
File Size Uploaded
django-smarttest-0.3.0.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-smarttest 0.3.0
File Interpreter ABI Platform
django_smarttest-0.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 22.0 kB

Release files / django-smarttest-0.3.0.tar.gz

Download URL django-smarttest-0.3.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e29c332df13fcad695f543943d04c805a3332e8258bc72ab4c57f4dc1db30863
BLAKE2b-256 checksum
How to use checksums
b27aea03a024de779642d72026a9cc51bc320f9ee34ac963a24d58020fc20ce4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_smarttest-0.3.0-py2.py3-none-any.whl

Download URL django_smarttest-0.3.0-py2.py3-none-any.whl
Size 12.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
63d02e53284ab86531d0bc7ee311b6c90d0e02883c7e8bd91a79c7d358066dbe
BLAKE2b-256 checksum
How to use checksums
247e06147f396bf884372f05388022e876e278da9d989d1c815b14a858f34f95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page