def run_tests(*args, **kwargs): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" coverage.use_cache(0) # Do not cache any of the coverage.py stuff coverage.start() test_results = django_test_runner(*args, **kwargs) # Stop code coverage after tests have completed coverage.stop() # Print code metrics header print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' # Report code coverage metrics coverage_modules = [] for module in settings.COVERAGE_MODULES: coverage_modules.append(__import__(module, globals(), locals(), [''])) coverage.report(coverage_modules, show_missing=1) # Print code metrics footer print '----------------------------------------------------------------------' return test_results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): # This doesn't work with Django 1.4 from django.test.simple import run_tests as django_test_runner import coverage coverage.use_cache(0) coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) coverage.stop() coverage_modules = [m.__file__ for k, m in sys.modules.iteritems() if m and k.split('.')[0] in test_labels and 'test' not in k] print print '='*80 print 'Coverage results for %s' % ', '.join(test_labels) print '='*80 coverage.report(coverage_modules, show_missing=1) coverage_html_dir = getattr(settings, 'COVERAGE_HTML_DIR', None) if coverage_html_dir is not None: coverage._the_coverage.html_report(coverage_modules, coverage_html_dir) return test_results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False): """ Test runner which displays a code coverage report at the end of the run. """ coverage.use_cache(0) coverage.start() if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: results = django_test_runner(test_labels, verbosity, interactive, extra_tests) coverage.stop() coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) if coverage_modules: coverage.report(coverage_modules, show_missing=1) return results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" coverage.use_cache(0) # Do not cache any of the coverage.py stuff coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) coverage.stop() coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_coverage_modules(app)) if coverage_modules: # Print code metrics header print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' coverage.report(coverage_modules, show_missing=1) # Print code metrics footer print '----------------------------------------------------------------------' return test_results
def run_tests(test_labels=("pages",), verbosity=1, interactive=True, extra_tests=[]): os.environ["DJANGO_SETTINGS_MODULE"] = "pages.testproj.test_settings" current_dirname = os.path.dirname(__file__) sys.path.insert(0, current_dirname) sys.path.insert(0, os.path.join(current_dirname, "../..")) from django.test.simple import run_tests as django_test_runner from django.db.models import get_app, get_apps if coverage: cov = coverage() cov.erase() cov.use_cache(0) cov.start() results = django_test_runner(test_labels, verbosity, interactive, extra_tests) if coverage: cov.stop() app = get_app("pages") modules = get_all_coverage_modules(app) cov.html_report(modules, directory="coverage") sys.exit(results)
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" # Start code coverage before anything else if necessary coverage_modules = [] for module_name in settings.COVERAGE_MODULES: app_name = module_name.split(".")[0] if (not test_labels) or (app_name in test_labels): coverage_modules.append(__import__(module_name, globals(), locals(), [''])) if hasattr(settings, 'COVERAGE_MODULES'): coverage.use_cache(0) # Do not cache any of the coverage.py stuff coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) # Stop code coverage after tests have completed if hasattr(settings, 'COVERAGE_MODULES'): coverage.stop() # Print code metrics header print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' coverage.report(coverage_modules, show_missing=1) # Print code metrics footer print '----------------------------------------------------------------------' else: print "No coverage modules defined in settings.py" return test_results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """ Custom test runner. Follows the django.test.simple.run_tests() interface. """ # Start code coverage before anything else if necessary if hasattr(settings, 'COVERAGE_MODULES'): coverage.use_cache(0) # Do not cache any of the coverage.py stuff coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) # Stop code coverage after tests have completed if hasattr(settings, 'COVERAGE_MODULES'): coverage.stop() # Print code metrics header print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' # Report code coverage metrics if hasattr(settings, 'COVERAGE_MODULES'): coverage_modules = [] for module in settings.COVERAGE_MODULES: coverage_modules.append(__import__(module, globals(), locals(), [''])) coverage.report(coverage_modules, show_missing=1) # Print code metrics footer print '----------------------------------------------------------------------' return test_results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" # Start code coverage before anything else if necessary cov = coverage.coverage() if hasattr(settings, "COVERAGE_MODULES") and not test_labels: cov.use_cache(0) # Do not cache any of the coverage.py stuff cov.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) # Stop code coverage after tests have completed if hasattr(settings, "COVERAGE_MODULES") and not test_labels: cov.stop() # Print code metrics header print "" print "----------------------------------------------------------------------" print " Unit Test Code Coverage Results" print "----------------------------------------------------------------------" # Report code coverage metrics if hasattr(settings, "COVERAGE_MODULES") and not test_labels: coverage_modules = [] for module in settings.COVERAGE_MODULES: coverage_modules.append(__import__(module, globals(), locals(), [""])) cov.report(coverage_modules, show_missing=1) # Print code metrics footer print "----------------------------------------------------------------------" # cov.html_report(directory='../docs/covhtml') return test_results
def run_tests(test_labels, verbosity=1,interactive=True, extra_tests=None, **kwargs): #Test runner that only runs tests for the apps listed in ``settings.TEST_APPS``. extra_tests = extra_tests or [] app_labels = getattr(settings, 'TEST_APPS', test_labels) return django_test_runner(app_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests, **kwargs)
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" site_name = settings.SETTINGS_MODULE.split(".")[0] output_dir = "/tmp/%s" % site_name # If the user provided modules on the command-line we'll only test the listed modules: if not test_labels: test_labels = [] for app in get_apps(): pkg = app.__package__ or "" # Avoid issue with Nones if pkg and pkg.startswith(site_name): test_labels.append(pkg.split(".")[-1]) test_labels.sort() logging.info("Automatically generated test labels for %s: %s", site_name, ", ".join(test_labels)) # Start code coverage before anything else if necessary use_coverage = hasattr(settings, 'COVERAGE_MODULES') and len(settings.COVERAGE_MODULES) if use_coverage: cov = coverage() cov.use_cache(0) # Do not cache any of the coverage.py stuff cov.exclude('^\s*$') # Exclude empty lines cov.exclude('^\s*#.*$') # Exclude comment blocks cov.exclude('^\s*(import|from)\s') # Exclude import statements cov.start() settings.DEBUG = False test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) # Stop code coverage after tests have completed if use_coverage: cov.stop() coverage_modules = filter(None, [ sys.modules[k] for k in sys.modules if any(l for l in test_labels if k.startswith(get_app(l).__package__)) ]) # Print code metrics header print '' print '-------------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '-------------------------------------------------------------------------' # Report code coverage metrics cov.report(coverage_modules) #cov.html_report(coverage_modules, directory=output_dir) #cov.xml_report(coverage_modules, outfile=os.path.join(output_dir, "coverage.xml")) # Print code metrics footer print '-------------------------------------------------------------------------' return test_results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): setup_test_environment() figleaf.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) figleaf.stop() if not os.path.isdir(os.path.join("temp", "figleaf")): os.mkdir(os.path.join("temp", "figleaf")) file_name = "temp/figleaf/test_output.figleaf" figleaf.write_coverage(file_name) output = commands.getoutput("figleaf2html " + file_name + " --output-directory=temp/figleaf") print output return test_results
def run_tests(test_labels=('pages',), verbosity=1, interactive=True, extra_tests=[]): cov = coverage() cov.erase() cov.use_cache(0) cov.start() app = get_app('pages') modules = get_all_coverage_modules(app, exclude_files=['auto_render.py']) results = django_test_runner(test_labels, verbosity, interactive, extra_tests) cov.stop() cov.html_report(modules, directory='coverage') sys.exit(results)
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): import coverage from django.test.simple import run_tests as django_test_runner from django.conf import settings coverage.use_cache(0) # Do not cache any of the coverage.py stuff coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) coverage.stop() coverage_modules = [] for module in settings.COVERAGE_MODULES: coverage_modules.append(__import__(module, globals(), locals(), [""])) coverage.report(coverage_modules, show_missing=0) return test_results
def run(self): this_dir = os.getcwd() testproj_dir = os.path.join(this_dir, "tracker/tests") os.chdir(testproj_dir) sys.path.insert(0, testproj_dir) from django.core.management import execute_manager os.environ["DJANGO_SETTINGS_MODULE"] = os.environ.get( "DJANGO_SETTINGS_MODULE", "settings") settings_file = os.environ["DJANGO_SETTINGS_MODULE"] settings_mod = __import__(settings_file, {}, {}, [""]) from django.test.simple import run_tests as django_test_runner results = django_test_runner(('tracker', ), verbosity=1, interactive=True, extra_tests=[]) os.chdir(this_dir)
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): setup_test_environment() figleaf.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) figleaf.stop() if not os.path.isdir(os.path.join("temp", "figleaf")): os.makedirs(os.path.join("temp", "figleaf")) file_name = "temp/figleaf/test_output.figleaf" figleaf.write_coverage(file_name) output = commands.getoutput("figleaf2html " + file_name + " --output-directory=temp/figleaf") print output return test_results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=None, **kwargs): """ Test runner that only runs tests for the apps listed in ``settings.TEST_APPS``. """ extra_tests = extra_tests or [] app_labels = getattr(settings, "TEST_APPS", test_labels) # Seems to be deleting the test database file twice :( from celery.utils import noop from django.db import connection connection.creation.destroy_test_db = noop return django_test_runner(app_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests, **kwargs)
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=None, **kwargs): """ Test runner that only runs tests for the apps listed in ``settings.TEST_APPS``. """ extra_tests = extra_tests or [] app_labels = getattr(settings, "TEST_APPS", test_labels) return django_test_runner(app_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests, **kwargs)
def run_tests(test_labels=("pages",), verbosity=1, interactive=True, extra_tests=[]): cov = coverage() cov.erase() cov.use_cache(0) cov.start() results = django_test_runner(test_labels, verbosity, interactive, extra_tests) cov.stop() app = get_app("pages") modules = get_all_coverage_modules(app) cov.html_report(modules, directory="coverage") sys.exit(results)
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): coverage_enabled = coverage and hasattr(settings, 'COVERAGE_MODULES') if coverage_enabled: coverage.use_cache(0) coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) if coverage_enabled: coverage.stop() coverage_modules = [] for module in settings.COVERAGE_MODULES: coverage_modules.append(__import__(module, globals(), locals(), [''])) coverage.report(coverage_modules, show_missing=1) return test_results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False): """ Test runner which displays a code coverage report at the end of the run. """ test_labels = test_labels or getattr(settings, "TEST_APPS", None) cover_branch = getattr(settings, "COVERAGE_BRANCH_COVERAGE", False) cov = coverage.coverage(branch=cover_branch, cover_pylib=False) cov.use_cache(0) cov.start() if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: from django.db import connection connection.creation.destroy_test_db = lambda *a, **k: None results = django_test_runner(test_labels, verbosity, interactive, extra_tests) cov.stop() coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) morfs = filter(is_wanted_module, coverage_modules) report_methd = cov.report if getattr(settings, "COVERAGE_HTML_REPORT", False) or \ os.environ.get("COVERAGE_HTML_REPORT"): output_dir = getattr(settings, "COVERAGE_HTML_DIRECTORY", "covhtml") report_method = curry(cov.html_report, directory=output_dir) else: report_method = cov.report morfs and report_method(morfs=morfs) return results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" import os, shutil, sys # Look for coverage.py in __file__/lib as well as sys.path sys.path = [os.path.join(os.path.dirname(__file__), "lib")] + sys.path import coverage from django.test.simple import run_tests as django_test_runner from django.conf import settings # Start code coverage before anything else if necessary #if hasattr(settings, 'COVERAGE_MODULES') and not test_labels: coverage.use_cache(0) # Do not cache any of the coverage.py stuff coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) # Stop code coverage after tests have completed #if hasattr(settings, 'COVERAGE_MODULES') and not test_labels: coverage.stop() # Print code metrics header print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' # Report code coverage metrics coverage_modules = [] if hasattr(settings, 'COVERAGE_MODULES') and (not test_labels or 'cms' in test_labels): for module in settings.COVERAGE_MODULES: coverage_modules.append( __import__(module, globals(), locals(), [''])) coverage.report(coverage_modules, show_missing=1) #Print code metrics footer print '----------------------------------------------------------------------' return test_results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False, xml_out=False): """ Test runner which displays a code coverage report at the end of the run. """ cov = coverage.coverage() cov.erase() cov.use_cache(0) cov.start() if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: results = django_test_runner(test_labels, verbosity, interactive, extra_tests) cov.stop() coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) if coverage_modules: if xml_out: # using the same output directory as the --xml function uses for testing if not os.path.isdir(os.path.join("temp", "xml")): os.makedirs(os.path.join("temp", "xml")) output_filename = 'temp/xml/coverage_output.xml' cov.xml_report(morfs=coverage_modules, outfile=output_filename) cov.report(coverage_modules, show_missing=1) return results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[], failfast=None): """ Custom test runner. Follows the django.test.simple.run_tests() interface. """ # Start code coverage before anything else if necessary if hasattr(settings, 'COVERAGE_MODULES'): cov = coverage.coverage() #coverage.use_cache(0) # Do not cache any of the coverage.py stuff cov.use_cache(0) # Do not cache any of the coverage.py stuff cov.start() test_results = django_test_runner(test_labels, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests, failfast=failfast) # Stop code coverage after tests have completed if hasattr(settings, 'COVERAGE_MODULES'): cov.stop() # Print code metrics header print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' # Report code coverage metrics if hasattr(settings, 'COVERAGE_MODULES'): coverage_modules = [] for module in settings.COVERAGE_MODULES: coverage_modules.append(__import__(module, globals(), locals(), [''])) cov.report(coverage_modules, show_missing=1) #cov.html_report(coverage_modules, directory='coverage_report') # Print code metrics footer print '----------------------------------------------------------------------' return test_results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" import os, shutil, sys # Look for coverage.py in __file__/lib as well as sys.path sys.path = [os.path.join(os.path.dirname(__file__), "lib")] + sys.path import coverage from django.test.simple import run_tests as django_test_runner from django.conf import settings # Start code coverage before anything else if necessary #if hasattr(settings, 'COVERAGE_MODULES') and not test_labels: coverage.use_cache(0) # Do not cache any of the coverage.py stuff coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) # Stop code coverage after tests have completed #if hasattr(settings, 'COVERAGE_MODULES') and not test_labels: coverage.stop() # Print code metrics header print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' # Report code coverage metrics coverage_modules = [] if hasattr(settings, 'COVERAGE_MODULES') and (not test_labels): for module in settings.COVERAGE_MODULES: coverage_modules.append(__import__(module, globals(), locals(), [''])) coverage.report(coverage_modules, show_missing=1) #Print code metrics footer print '----------------------------------------------------------------------' return test_results
def test_runner(test_labels, verbosity=1, interactive=True, extra_tests=[]): coveragemodules = [] if hasattr(settings, 'COVERAGE_MODULES'): coveragemodules = settings.COVERAGE_MODULES if coveragemodules and not test_labels: coverage.use_cache(0) coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) if coveragemodules and not test_labels: coverage.stop() print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' modules = [] for module_string in coveragemodules: modules.append(__import__(module_string, globals(), locals(), [""])) coverage.report(modules, show_missing=1) print '----------------------------------------------------------------------' return test_results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" cov = coverage.coverage() cov.use_cache(0) # Do not cache any of the coverage.py stuff cov.exclude('def __unicode__') cov.exclude('def get_absolute_url') cov.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) cov.stop() report_dir = getattr(settings, 'COVERAGE_REPORT', None) if report_dir is not None: cov.html_report(directory=report_dir) coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_coverage_modules(app)) if coverage_modules: # Print code metrics header print '' print '----------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '----------------------------------------------------------------------' cov.report(coverage_modules, show_missing=1) # Print code metrics footer print '----------------------------------------------------------------------' return test_results
def runtests(): failures = django_test_runner(['fullhistory'], verbosity=1, interactive=True) sys.exit(failures)
def runtests(): failures = django_test_runner(['localedb'], verbosity=1, interactive=True) sys.exit(failures)
def runtests(): failures = django_test_runner(['dagcategory'], verbosity=1, interactive=True) sys.exit(failures)
def runtests(): failures = django_test_runner(['reportengine'], verbosity=1, interactive=True) sys.exit(failures)
def run_tests(test_labels=('pages',), verbosity=1, interactive=True, extra_tests=[]): results = django_test_runner(test_labels, verbosity, interactive, extra_tests) sys.exit(results)
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False, xml_out=False, callgraph=False, html_only=False): """ Test runner which displays a code coverage report at the end of the run. """ cov = coverage.coverage() cov.erase() cov.use_cache(0) test_labels = test_labels or getattr(settings, "TEST_APPS", None) cover_branch = getattr(settings, "COVERAGE_BRANCH_COVERAGE", False) cov = coverage.coverage(branch=cover_branch, cover_pylib=False) cov.use_cache(0) coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) morfs = filter(is_wanted_module, coverage_modules) if callgraph: try: import pycallgraph #_include = [i.__name__ for i in coverage_modules] _included = getattr(settings, "COVERAGE_INCLUDE_MODULES", []) _excluded = getattr(settings, "COVERAGE_EXCLUDE_MODULES", []) _included = [i.strip('*')+'*' for i in _included] _excluded = [i.strip('*')+'*' for i in _included] _filter_func = pycallgraph.GlobbingFilter( include=_included or ['*'], #include=['lotericas.*'], #exclude=[], #max_depth=options.max_depth, ) pycallgraph_enabled = True except ImportError: pycallgraph_enabled = False else: pycallgraph_enabled = False cov.start() if pycallgraph_enabled: pycallgraph.start_trace(filter_func=_filter_func) if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: tr = django_test_runner(verbosity, interactive) results = tr.run_tests(test_labels, extra_tests) #results = django_test_runner(test_labels, verbosity, interactive, # extra_tests) if callgraph and pycallgraph_enabled: pycallgraph.stop_trace() cov.stop() if getattr(settings, "COVERAGE_HTML_REPORT", False) or \ os.environ.get("COVERAGE_HTML_REPORT"): output_dir = getattr(settings, "COVERAGE_HTML_DIRECTORY", "covhtml") report_method = curry(cov.html_report, directory=output_dir) if callgraph and pycallgraph_enabled: callgraph_path = output_dir + '/' + 'callgraph.png' pycallgraph.make_dot_graph(callgraph_path) print >>sys.stdout print >>sys.stdout, "Coverage HTML reports were output to '%s'" %output_dir if callgraph: if pycallgraph_enabled: print >>sys.stdout, "Call graph was output to '%s'" %callgraph_path else: print >>sys.stdout, "Call graph was not generated: Install 'pycallgraph' module to do so" else: report_method = cov.report if coverage_modules: if xml_out: # using the same output directory as the --xml function uses for testing if not os.path.isdir(os.path.join("temp", "xml")): os.makedirs(os.path.join("temp", "xml")) output_filename = 'temp/xml/coverage_output.xml' cov.xml_report(morfs=coverage_modules, outfile=output_filename) if not html_only: cov.report(coverage_modules, show_missing=1) return results
def runtests(): failures = django_test_runner(['configstore'], verbosity=1, interactive=True) sys.exit(failures)
def runtests(): failures = django_test_runner(['fieldmaker'], verbosity=1, interactive=True) sys.exit(failures)
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" site_name = settings.SETTINGS_MODULE.split(".")[0] output_dir = "/tmp/%s" % site_name # If the user provided modules on the command-line we'll only test the listed modules: if not test_labels: test_labels = [] for app in get_apps(): pkg = app.__package__ or "" # Avoid issue with Nones if pkg and pkg.startswith(site_name): test_labels.append(pkg.split(".")[-1]) test_labels.sort() logging.info("Automatically generated test labels for %s: %s", site_name, ", ".join(test_labels)) # Start code coverage before anything else if necessary use_coverage = hasattr(settings, 'COVERAGE_MODULES') and len( settings.COVERAGE_MODULES) if use_coverage: cov = coverage() cov.use_cache(0) # Do not cache any of the coverage.py stuff cov.exclude('^\s*$') # Exclude empty lines cov.exclude('^\s*#.*$') # Exclude comment blocks cov.exclude('^\s*(import|from)\s') # Exclude import statements cov.start() settings.DEBUG = False test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) # Stop code coverage after tests have completed if use_coverage: cov.stop() coverage_modules = filter(None, [ sys.modules[k] for k in sys.modules if any(l for l in test_labels if k.startswith(get_app(l).__package__)) ]) # Print code metrics header print '' print '-------------------------------------------------------------------------' print ' Unit Test Code Coverage Results' print '-------------------------------------------------------------------------' # Report code coverage metrics cov.report(coverage_modules) #cov.html_report(coverage_modules, directory=output_dir) #cov.xml_report(coverage_modules, outfile=os.path.join(output_dir, "coverage.xml")) # Print code metrics footer print '-------------------------------------------------------------------------' return test_results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False, xml_out=False, callgraph=False): """ Test runner which displays a code coverage report at the end of the run. """ cov = coverage.coverage() cov.erase() cov.use_cache(0) test_labels = test_labels or getattr(settings, "TEST_APPS", None) cover_branch = getattr(settings, "COVERAGE_BRANCH_COVERAGE", False) cov = coverage.coverage(branch=cover_branch, cover_pylib=False) cov.use_cache(0) coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) morfs = filter(is_wanted_module, coverage_modules) if callgraph: try: import pycallgraph #_include = [i.__name__ for i in coverage_modules] _included = getattr(settings, "COVERAGE_INCLUDE_MODULES", []) _excluded = getattr(settings, "COVERAGE_EXCLUDE_MODULES", []) _included = [i.strip('*') + '*' for i in _included] _excluded = [i.strip('*') + '*' for i in _included] _filter_func = pycallgraph.GlobbingFilter( include=_included or ['*'], #include=['lotericas.*'], #exclude=[], #max_depth=options.max_depth, ) pycallgraph_enabled = True except ImportError: pycallgraph_enabled = False else: pycallgraph_enabled = False cov.start() if pycallgraph_enabled: pycallgraph.start_trace(filter_func=_filter_func) if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: results = django_test_runner(test_labels, verbosity, interactive, extra_tests) if callgraph and pycallgraph_enabled: pycallgraph.stop_trace() cov.stop() report_methd = cov.report if getattr(settings, "COVERAGE_HTML_REPORT", False) or \ os.environ.get("COVERAGE_HTML_REPORT"): output_dir = getattr(settings, "COVERAGE_HTML_DIRECTORY", "covhtml") report_method = curry(cov.html_report, directory=output_dir) if callgraph and pycallgraph_enabled: callgraph_path = output_dir + '/' + 'callgraph.png' pycallgraph.make_dot_graph(callgraph_path) print >> sys.stdout print >> sys.stdout, "Coverage HTML reports were output to '%s'" % output_dir if callgraph: if pycallgraph_enabled: print >> sys.stdout, "Call graph was output to '%s'" % callgraph_path else: print >> sys.stdout, "Call graph was not generated: Install 'pycallgraph' module to do so" else: report_method = cov.report if coverage_modules: if xml_out: # using the same output directory as the --xml function uses for testing if not os.path.isdir(os.path.join("temp", "xml")): os.makedirs(os.path.join("temp", "xml")) output_filename = 'temp/xml/coverage_output.xml' cov.xml_report(morfs=coverage_modules, outfile=output_filename) cov.report(coverage_modules, show_missing=1) return results
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]): """Custom test runner. Follows the django.test.simple.run_tests() interface.""" print "cs test_runner_with_coverage " + str(getattr(settings, 'COVERAGE_MODULES')) + " , " + str(test_labels) coverage.use_cache(0) # Do not cache any of the coverage.py stuff coverage.start() # Start code coverage before anything else if necessary # if hasattr(settings, 'COVERAGE_MODULES') and not test_labels: # print "cs coverage start" # coverage.use_cache(0) # Do not cache any of the coverage.py stuff # coverage.start() test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests) coverage.stop() if not os.path.exists(settings.COVERAGE_DIR): os.makedirs(settings.COVERAGE_DIR) coverage.html_report(directory='coverage') coverage.erase(); # Stop code coverage after tests have completed # if hasattr(settings, 'COVERAGE_MODULES') and not test_labels: # coverage.stop() # # # Print code metrics header # print '' # print '----------------------------------------------------------------------' # print ' Unit Test Code Coverage Results' # print '----------------------------------------------------------------------' # coverage_modules = [] # for module in settings.COVERAGE_MODULES: # coverage_modules.append(__import__(module, globals(), locals(), [''])) # # print "cs coverage_modules: " + str(coverage_modules) # for module_string in settings.COVERAGE_MODULES: # module = __import__(module_string, globals(), locals(), [""]) # f,s,m,mf = coverage.analysis(module) # fp = file(os.path.join(settings.COVERAGE_DIR, module_string + ".html"), "wb") # coverage_color.colorize_file(f, outstream=fp, not_covered=mf) # fp.close() # coverage.report(coverage_modules, show_missing=1) # coverage.erase(); # Report code coverage metrics # if hasattr(settings, 'COVERAGE_MODULES') and not test_labels: # coverage_modules = [] # for module in settings.COVERAGE_MODULES: # coverage_modules.append(__import__(module, globals(), locals(), [''])) # # coverage.report(coverage_modules, show_missing=1) # Print code metrics footer # print '----------------------------------------------------------------------' return test_results
def runtests(): failures = django_test_runner(['form_designer'], verbosity=1, interactive=True) sys.exit(failures)
def run_tests( test_labels=('mptt', ), verbosity=1, interactive=True, extra_tests=[]): results = django_test_runner(test_labels, verbosity, interactive, extra_tests) sys.exit(results)