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. find even number by Rajeev529 1 month, 1 week ago
  2. Form field with fixed value by roam 1 month, 4 weeks ago
  3. New Snippet! by Antoliny0919 2 months, 1 week ago
  4. Add Toggle Switch Widget to Django Forms by OgliariNatan 4 months, 3 weeks ago
  5. get_object_or_none by azwdevops 8 months, 2 weeks ago

Comments

Please login first before commenting.