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
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.