Login

Custom nose runner

Author:
tomas
Posted:
June 4, 2009
Language:
Python
Version:
1.0
Score:
1 (after 1 ratings)

This method is replacement for django test runner. It uses nose test runner, which will discover all tests in the application (not even in tests module of applications).

For installing put in settings.py: TEST_RUNNER = 'nose_runner.run_tests'

where nose_runner is module containing the code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from django.test.utils import setup_test_environment, teardown_test_environment
from nose.core import TextTestRunner
from nose.loader import defaultTestLoader
import settings

def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    setup_test_environment()
    
    settings.DEBUG = False    
    

    old_name = settings.DATABASE_NAME
    from django.db import connection
    connection.creation.create_test_db(verbosity, autoclobber=not interactive)
    
    if test_labels:
        suite = defaultTestLoader().loadTestsFromNames(test_labels)
    else:
        suite = defaultTestLoader().loadTestsFromName('.')
    result = TextTestRunner(verbosity=verbosity).run(suite)
    
    connection.creation.destroy_test_db(old_name, verbosity)
    
    
    teardown_test_environment()
    
    return len(result.failures) + len(result.errors)
    

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 6 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 6 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 1 month ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 2 months ago
  5. Help text hyperlinks by sa2812 1 year, 2 months ago

Comments

Please login first before commenting.