Login

Custom nose runner

Author:
tomas
Posted:
June 4, 2009
Language:
Python
Version:
1.0
Tags:
test nose testrunner
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

Comments

Please login first before commenting.